没有设置我有一个春天控制器,它是把一个变量在会话:Session变量春
public class LoginFormController extends SimpleFormController {
public ModelAndView onSubmit(HttpServletRequest request,
HttpServletResponse response, Object command) throws Exception {
request.getSession().setAttribute("authenticated_user", "authenticated_user");
}
}
然后我有一个HandlerInterceptor接口。在preHandle方法,我检查变量会话:
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response,
Object handler) throws Exception {
/* first, check if the requested view even required authentication */
if (isAuthenticationRequired(request)) {
/* check to see that user is logged in */
if (null == request.getSession().getAttribute("authenticated_user")) {
forwardToLogonPage(request, response);
return false;
}
/* all is ok - pass the request on */
return true;
}
/* all is ok - pass the request on */
return true;
}
问题是,它似乎是会话变量没有被自request.getSession()设置的getAttribute(“AUTHENTICATED_USER”))始终。解决为空。
任何想法plz?
感谢, Krt_Malta
BDW Request对象...的isAuthenticationRequired方法效果很好,我测试了它。 – 2010-10-20 06:41:26
问题实际上是onSubmit()方法没有被调用... – 2010-10-20 07:15:23