struts2中登錄過濾器取得request實例與傳參

 
public String intercept(ActionInvocation invocation) throws Exception {
		ActionContext ctx = invocation.getInvocationContext();     
		HttpServletRequest request = (HttpServletRequest)ctx.get(ServletActionContext.HTTP_REQUEST);
		
		
		System.out.println(request.getParameter("url"));
		System.out.println(request.getRequestURI());
		System.out.println(request.getServletPath()); 
		
		
		
		
		String invocationAction=invocation.getAction().getClass().getName();		
		String invocationName=invocationAction.substring(invocationAction.lastIndexOf(".")+1,invocationAction.length());
		if(invocationName.toLowerCase().endsWith("scope"))
		{		
			if(invocation.getInvocationContext().getSession().get("user")==null)
				return BaseAction.USER;
		}
		if(invocationName.toLowerCase().endsWith("stage"))
		{
			if(invocation.getInvocationContext().getSession().get("operator")==null)
				return Action.LOGIN;
		}
		return invocation.invoke();
	}

 

傳參經過java

 public String intercept(ActionInvocation invocation) throws Exception   url

  •     {   
  •         ActionContext ctx = invocation.getInvocationContext();   
  •         String user = (String)ctx.getSession().get("username");   
  •         System.out.print(user);   
  •         if (user != null)   
  •         {   
  •             return invocation.invoke();   
  •         }   
  •         System.out.print(user);   
  •         ctx.put("tip""您尚未登陸,請登錄系統");   
  •         return Action.LOGIN;   
  •     }   

    便可在頁面中獲得
    spa

  • 相關文章
    相關標籤/搜索