本人自己配的拦截器,就是不执行,求各位大神解答,谢谢
struts2吧
全部回复
仅看楼主
level 1
扫荡地球 楼主
拦截器类
package com.action;
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.AbstractInterceptor;
public class AuthInterceptor extends AbstractInterceptor
{
private static final long serialVersionUID = 49996560
15743518872
L;
public void init(){
System.out.print("00000000000000000000");
}
public String intercept(ActionInvocation invocation) throws Exception
{
System.out.println("1111111111111111111111");
Map map = invocation.getInvocationContext().getSession();
System.out.println("333333333333333333");
if(map.get("username") == null)
{
return Action.LOGIN;
}
else
{
return invocation.invoke();
}
}
}
2014年09月18日 01点09分 1
level 1
扫荡地球 楼主
就是一个简单的登录验证,按照网上的做法配置的。如果有登陆信息且正确则index.jsp能跳到hello.jsp 但是现在直接在域名中输入hello.jsp也能直接进去。
console中能输出拦截器中init的 000000 intercept方法里面两个均输出不了
2014年09月18日 02点09分 3
level 1
扫荡地球 楼主
<struts>
<constant name="struts.devMode" value="true" />
<package name="default" namespace="/" extends="struts-default">
<interceptors>
<interceptor name="AuthInterceptor" class="com.action.AuthInterceptor"></interceptor>
<interceptor-stack name="default">
<interceptor-ref name="AuthInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>
<global-results>
<result name="login" type="redirect">/index.jsp</result>
</global-results>
<action name="Login" class="com.action.LoginAction" method="execute">
<result name="success">/hello.jsp
</result>
<result name="fail">/index.jsp
</result>
</action>
</package>
</struts>
2014年09月18日 02点09分 4
1