struts2拦截器使用
2014-11-24 16:26
169 查看
<package name="testLogin" namespace="/" extends="struts-default">
<!-- 拦截器 -->
<interceptors>
<interceptor name="myInterceptor" class="com.interceptor.MyInterceptor"></interceptor>
<!-- 定义公共的拦截器链,在action标签中只需要引用拦截器链 -->
<interceptor-stack name="defaultstack1">
<interceptor-ref name="myInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="demo" class="com.action.LoginAction">
<result name="error" type="redirect">/error.jsp</result>
<result name="success">/success.jsp</result>
<result name="checkError">/checkSession.jsp</result>
<interceptor-ref name="defaultstack1"></interceptor-ref>
</action>
</package>
这时定义一个全局的interceptor
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="globalMessages"/>
<constant name="struts.i18n.encoding" value="GBK"/>
<!--<constant name="struts.enable.DynamicMethodInvocation" value="true" />-->
<package name="user" extends="struts-default" >
<interceptors>
<interceptor name="MyInterceptor" class="com.gxk.test.MyInterceptor"/>
</interceptors>
<global-results>
<result name="login">/login.jsp</result>
</global-results>
<action name="login" class="com.gxk.test.Login">
<result>/interceptor/welcome.jsp</result>
<result name="error">/interceptor/error.jsp</result>
</action>
<action name="viewBook">
<result>/interceptor/viewBook.jsp</result>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="MyInterceptor"/>
</action>
</package>
</struts>
这时定义一个单独的action的interceptor,<global-results>定义了一个全局的login, 采用struts2的全局result配置,定义类中的返回类型是login,则转向login.jsp
<!-- 拦截器 -->
<interceptors>
<interceptor name="myInterceptor" class="com.interceptor.MyInterceptor"></interceptor>
<!-- 定义公共的拦截器链,在action标签中只需要引用拦截器链 -->
<interceptor-stack name="defaultstack1">
<interceptor-ref name="myInterceptor"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>
</interceptor-stack>
</interceptors>
<action name="demo" class="com.action.LoginAction">
<result name="error" type="redirect">/error.jsp</result>
<result name="success">/success.jsp</result>
<result name="checkError">/checkSession.jsp</result>
<interceptor-ref name="defaultstack1"></interceptor-ref>
</action>
</package>
这时定义一个全局的interceptor
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<constant name="struts.custom.i18n.resources" value="globalMessages"/>
<constant name="struts.i18n.encoding" value="GBK"/>
<!--<constant name="struts.enable.DynamicMethodInvocation" value="true" />-->
<package name="user" extends="struts-default" >
<interceptors>
<interceptor name="MyInterceptor" class="com.gxk.test.MyInterceptor"/>
</interceptors>
<global-results>
<result name="login">/login.jsp</result>
</global-results>
<action name="login" class="com.gxk.test.Login">
<result>/interceptor/welcome.jsp</result>
<result name="error">/interceptor/error.jsp</result>
</action>
<action name="viewBook">
<result>/interceptor/viewBook.jsp</result>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="MyInterceptor"/>
</action>
</package>
</struts>
这时定义一个单独的action的interceptor,<global-results>定义了一个全局的login, 采用struts2的全局result配置,定义类中的返回类型是login,则转向login.jsp
相关文章推荐
- Struts2拦截器的使用
- 在struts2中使用拦截器(Interceptor)控制登录和权限
- Struts2使用15 -- 拦截器5 -- 实例
- Struts2拦截器的使用(详解)
- 使用Struts2的拦截器实现权限控制
- struts2拦截器的使用
- Struts2拦截器的使用
- Struts2使用13 -- 拦截器3 -- 内置拦截器
- Struts2使用12 -- 拦截器2 -- 配置
- Struts2拦截器的使用
- Struts2拦截器的使用 (详解)
- Struts2拦截器的使用收藏
- struts2:使用拦截器注解
- Struts2使用14 -- 拦截器4 -- 自定义拦截器
- Struts2的拦截器使用
- 在struts2中使用拦截器(Interceptor)控制登录和权限
- struts2:使用拦截器注解
- 在struts2中使用拦截器(Interceptor)控制登录和权限
- struts2使用拦截器时产生java.lang.IllegalStateException异常解决办法
- Struts2拦截器的使用