struts拦截器采用的是责任链的模式(chain of responsibility),使用的是aop思想,所以每个拦截器内部一定是使用动态代理模式,既然使用动态代理模式,一定就是对action的装饰,既然是action,我们至少有两种方式实现跳转到指定页面。
一种是,采用request、respons方式:
HttpServletResponse response = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
String location = request.getContextPath() + "/errorAwake.jsp";
response.sendRedirect(location);
return null;
注意,因为采用原始的request,response方式,需要return null;
一种是,采用action方式:
if (!invocation.getInvocationContext().getSession().isEmpty()) {
Map<String, Object> map = invocation.getInvocationContext().getSession();
if (null == map.get("user")) {
return Action.LOGIN;
}
}
如上面代码所示,直接方法一个字符串。此时需要在struts.xml中配置:
<global-results>
<result name="login">/login.jsp</result>
</global-results>
粗浅理解,还望同学们指正。
欢迎阅读相关文章:http://hi.youkuaiyun.com/linchengzhi