- public class AuthInterceptor extends MethodFilterInterceptor {
- protected String doIntercept(ActionInvocation invocation) throws Exception {
- ActionContext ctx = invocation.getInvocationContext();
- HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
- HttpSession session = request.getSession();
- UserBean user = (UserBean) session.getAttribute("currentUser");
- if (null == user) {
- request.setAttribute("param1", "index.jsp");
- request.setAttribute("param2", new Integer(111));
- return Action.ERROR;
- }
- return invocation.invoke();
- }
- }
public class AuthInterceptor extends MethodFilterInterceptor {
protected String doIntercept(ActionInvocation invocation) throws Exception {
ActionContext ctx = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
HttpSession session = request.getSession();
UserBean user = (UserBean) session.getAttribute("currentUser");
if (null == user) {
request.setAttribute("param1", "index.jsp");
request.setAttribute("param2", new Integer(111));
return Action.ERROR;
}
return invocation.invoke();
}
}
設置缺省的interceptor-stack
- <interceptors>
- <interceptor name="auth" class="com.mice.AuthInterceptor"/>
- <interceptor-stack name="miceStack">
- <interceptor-ref name="defaultStack"/>
- <interceptor-ref name="auth"/>
- </interceptor-stack>
- </interceptors>
- <default-interceptor-ref name="miceStack"/>
- < global-results>
- <result name="error">/messagePage.jsp</result>
- </global-results>
<interceptors>
<interceptor name="auth" class="com.mice.AuthInterceptor"/>
<interceptor-stack name="miceStack">
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="auth"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="miceStack"/>
< global-results>
<result name="error">/messagePage.jsp</result>
</global-results>
但是在messagePage.jsp中,request.getAttribute取不到param1和param2, 請問有什麼辦法可以在interceptor中設置HttpServeletRequest的參數?