日期:2014-05-18  浏览次数:20568 次

struts2关于拦截器的配置问题
今天我快要吐血了,写了一个自己的拦截器,想试试功能的。哪知道问题频出,从昨天晚上一直到今天晚上。
这个project里面只有3个文件,index.jsp,welcome.jsp,login.jsp,只有一个action和一个interceptor,interceptor继承的是abstractInterceptor,老是报这种错误。
<struts>

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

    <package name="default" namespace="/" extends="struts-default">
        <interceptors>
<interceptor name="mySimple" class="com.dong.chun.interceptor.MyInterceptor"></interceptor>
</interceptors>
        
        <global-results>
            <result name="login">/login.jsp</result>
        </global-results>
       
        <action name="loginAction" class="com.dong.chun.action.LoginAction">
<interceptor-ref name="my"></interceptor-ref>
<interceptor-ref name="defaultStack"></interceptor-ref>

<result name="SUCCESS">/welcome.jsp</result>

</action>
    </package>
</struts>
下面详细说明错误出现的过程
------解决方案--------------------
引用:
对不起各位找到错误 。现在不报错了。但是不能拦截使他跳转到login.jsp页面。。。

我的逻辑是这样的:
    index.jsp 只有简单的一句话
    welcome.jsp 也是只有一句话
    login.jsp 里面是一个表单,用户注册
    MyInterceptor.java 里面是判断session有没有user的值,没有就返回Action.LOGIN;
    LoginAction.java 就是两个属性,各自的get,set方法
现在直接在浏览器上敲http://localhost:8080/工程名/
竟然可以直接跳到index.jsp,拦截器为什么不拦截呢
因为你web.xml文件中的初始页面就是index.jsp