• 【 Struts2 过滤器】


    LoginInterceptor
    package k.util;
    
    import com.opensymphony.xwork2.ActionInvocation;
    import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
    import org.apache.struts2.ServletActionContext;
    
    import javax.servlet.http.HttpServletRequest;
    
    public class LoginInterceptor extends MethodFilterInterceptor {
        @Override
        protected String doIntercept(ActionInvocation actionInvocation) throws Exception {
            HttpServletRequest request = ServletActionContext.getRequest();
            Object name = request.getSession().getAttribute("name");
             return name == null ? "toLogin" : actionInvocation.invoke();
        }
    }

    struts.xml

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
            "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
            "http://struts.apache.org/dtds/struts-2.3.dtd">
    <struts>
        <constant name="struts.i18n.encoding" value="UTF-8"></constant>
        <package name="struts2-hibernate" extends="struts-default" namespace="/">
            <interceptors>
                <interceptor name="LoginInterceptor" class="k.util.LoginInterceptor">
                    <param name="excludeMethods">toLogin,login</param>
                </interceptor>
            </interceptors>
            <action name="student_*" class="k.action.StudentAction" method="{1}">
                <interceptor-ref name="LoginInterceptor"></interceptor-ref>
                <interceptor-ref name="defaultStack"></interceptor-ref>
                <result name="list" type="redirectAction">student_list</result>
                <result name="toList">/WEB-INF/student/list.jsp</result>
                <result name="toAdd">/WEB-INF/student/add.jsp</result>
                <result name="toUpdate">/WEB-INF/student/update.jsp</result>
                <result name="toLogin">/WEB-INF/student/login.jsp</result>
            </action>
        </package>
    </struts>
  • 相关阅读:
    day02_07 创建新目录
    day02_04 字典
    day02_02 列表切割
    day03_01 文件操作
    MS的TREE 控件使用
    使用自定义用户控件的一些经验
    Asp.net开发心得点滴[动态加载的用户控件使用事件委托,交给页面处理的事件无效问题]
    正则表达式基础学习[1]
    自定义控件无法在VS.net编辑中显示
    错误的递归
  • 原文地址:https://www.cnblogs.com/kikyoqiang/p/12364154.html
Copyright © 2020-2023  润新知