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的参数?
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值