首页 > 其他 > 详细

四、在struts2中自定义拦截器后,程序运行时validate方法为什么没起作用

时间:2015-03-11 02:27:50      阅读:309      评论:0      收藏:0      [点我收藏+]

出现的问题是:在struts2中自定义拦截器后,程序运行时validate方法没有执行,这是怎么回事呢?

?

与项目问题相关的文件如下:

1、struts.xml文件

bubuko.com,布布扣
?

2、Action类中的部分代码是如下实现的,出现的问题是添加了自定义拦截器后,validate方法就不执行了,直接执行execute方法


bubuko.com,布布扣
上述问题出现的原因是什么呢?问题怎么解决呢?

回答:问题出现的原因是自定义的拦截器配置在struts.xml配置文件中后,还要手动引入defaultStack拦截器栈。否则defaultStack拦截器栈中所有拦截器的功能都无法实现。

?

struts.xml的配置应当是:

<struts>	
    <package name="example" namespace="/" extends="struts-default">
    	<interceptors>
    		<interceptor name="userInterceptor" class="com.yanln.test.action.UserInterceptor"></interceptor>
    	</interceptors>
    	<default-interceptor-ref name="defaultStack"></default-interceptor-ref> 
    	<global-results>
    		<result name="login">login.jsp</result>
    	</global-results>
        <action name="login" class="com.yanln.test.action.LoginAction">
            <interceptor-ref name="userInterceptor"></interceptor-ref> 
            <result name="success" type="redirectAction">indexAction</result>
            <result name="input">index.jsp</result>
        </action>
         <action name="indexAction" class="com.yanln.test.action.IndexAction">  
            <result name="showSystem">success.jsp</result>
        </action>
    </package>
</struts>

?或者是:

<struts>	
    <package name="example" namespace="/" extends="struts-default">
    	<interceptors>
    		<interceptor name="userInterceptor" class="com.yanln.test.action.UserInterceptor"></interceptor>
    		<interceptor-stack name="mystack">
        		<interceptor-ref name="defaultStack"></interceptor-ref>
        		<interceptor-ref name="userInterceptor"></interceptor-ref>
        	</interceptor-stack>
    	</interceptors>
    	<default-interceptor-ref name="mystack"></default-interceptor-ref> 
    	<global-results>
    		<result name="login">login.jsp</result>
    	</global-results>
        <action name="login" class="com.yanln.test.action.LoginAction">        	
            <result name="success" type="redirectAction">indexAction</result>
            <result name="input">index.jsp</result>
        </action>
         <action name="indexAction" class="com.yanln.test.action.IndexAction"> 
            <result name="showSystem">success.jsp</result>
        </action>
    </package>
</struts>

?

?

?

?

?

四、在struts2中自定义拦截器后,程序运行时validate方法为什么没起作用

原文:http://yanln.iteye.com/blog/2190978

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!