Interceptor中設置request參數問題

爲了驗證身份,寫了一個interceptor,驗證失敗就dispatch到messagePage.jsp,messagePage.jsp是遺留系統的頁面不能改動:

Java代碼
  1. public class AuthInterceptor extends MethodFilterInterceptor {   
  2.   
  3.   
  4.     protected String doIntercept(ActionInvocation invocation) throws Exception {   
  5.   
  6.         ActionContext ctx = invocation.getInvocationContext();   
  7.         HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);   
  8.         HttpSession session = request.getSession();   
  9.                 UserBean user = (UserBean) session.getAttribute("currentUser");   
  10.         if (null == user)  {   
  11.             request.setAttribute("param1""index.jsp");   
  12.             request.setAttribute("param2"new Integer(111));   
  13.             return Action.ERROR;   
  14.                
  15.         }   
  16.             
  17.            
  18.         return invocation.invoke();   
  19.        
  20.     }   
  21.        
  22.   
  23. }  
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
Java代碼
  1. <interceptors>   
  2.         <interceptor name="auth" class="com.mice.AuthInterceptor"/>   
  3.         <interceptor-stack name="miceStack">   
  4.                
  5.             <interceptor-ref name="defaultStack"/>   
  6.             <interceptor-ref name="auth"/>   
  7.         </interceptor-stack>   
  8.                </interceptors>   
  9. <default-interceptor-ref name="miceStack"/>   
  10.   
  11. < global-results>   
  12.         <result name="error">/messagePage.jsp</result>   
  13.       </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的參數?
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章