今天修复一个以前的问题登陆的问题。
1、一个验证的 filter 拦截所有没鉴权的请求,鉴权的方式是:判断session中是否纯在user对象。(当然,如果是向loginAction 发出的请求,不用鉴权就允许其通过的,否则就死循环了,对吧。)
2、loginAction 鉴权通过后 Dispatch 到 index.jsp。
public String login() throws Exception
{
//一些业务逻辑 ... 如果鉴权通过,会把user 放到session中去 ActionContext.getContext().getSession().put('user', guser);
url = config.getValue("HomePage"); //读取配置文件中的首页路径
return "redirect";
}
<action name="login" class="loginAction" method="login">
<result name="dispatcher" type="dispatcher">${url}</result>
<result name="redirect" type="redirect">${url}</result>
<result name="httpheader" type="httpheader">${url}</result>
<result name="success" type="redirect" >/admin/Main.jsp</result>
<result name="error" >/admin/common/error.jsp</result>
</action>
看似没有问题,可以当我的配置文件是这样的时候
HomePage=http://172.0.0.1:8080/index.jsp
你在跳转上是完全没有问题的,程序会向${HomePage} 去Dispatch。
在程序会向${HomePage} 去Dispatch的时候,依然进入到 鉴权的filter 中来了。这次进来,你觉得filter 应该不会难为你了,让你奔向${HomePage} 对吧。。。
sorry,不行! 原因是 filter 说 session 中没有user 对象!!!
怎么回事?! 当我 在filter 中 System.out.println(request.getSession().getId()); 以及 在 loginAction 中 System.out.println(request.getSession().getId()); 后,我傻眼了,两个sessionid 不一致。那为毛不一致呢?在这其间我什么都没干啊,程序只进行了个 dispatch 呀。
或许症结是这个 dispatch 了,我猜。 然后我试着改。
HomePage=/index.jsp
咦好了。
bug 算 OK了,可是这到底是为什么!!!dispatch 带上http 难道就是 相当于 我关掉浏览器 再打开浏览器的效果了?!望大虾指教。