struts2注解式拦截器

@Controller
@Namespace("/category")
@ParentPackage("news")
@InterceptorRef(value = "isLoginInterceptor")
public class CategoryAction extends ActionSupport {

虽然这样子注解就可以应用拦截器,但spring并不会自动帮你生成注解器实例,还需要在strutsx.xml中配置

<struts>
    
    <constant name="struts.i18n.encoding" value="UTF-8"/>

    
    <constant name="struts.action.extension" value="action,do,html"/>

    
    <constant name="struts.configuration.xml.reload" value="true"/>

    
    <constant name="struts.devMode" value="false"/>  

    
    <constant name="struts.serve.static.browserCache" value="false" />

    
    <constant name="struts.objectFactory" value="spring" />

    
    <constant name="struts.enable.DynamicMethodInvocation" value="false"/>

    
    <package name="news" extends="struts-default">
        <interceptors>
            <interceptor name="loginCheckInterceptor" class="com.news.interceptor.IsLoginInterceptor">interceptor>
            <interceptor-stack name="isLoginInterceptor">
                <interceptor-ref name="loginCheckInterceptor">interceptor-ref>
                <interceptor-ref name="defaultStack">interceptor-ref>
            interceptor-stack>
        interceptors>
    package>
struts>

你可能感兴趣的:(struts2)