如何在struts2中登录后跳转到前置页面

  • package actions; 
  • import javax.servlet.http.HttpServletRequest; 
  • import javax.servlet.http.HttpSession; 
  • import org.apache.struts2.ServletActionContext; 
  • import com.opensymphony.xwork2.ActionInvocation; 
  • import com.opensymphony.xwork2.interceptor.AbstractInterceptor; 
  • public class AuthorizationInterceptor extends AbstractInterceptor 
  • private static final long serialVersionUID = 2071704648277594728L; 
  • public String intercept(ActionInvocation invocation) throws Exception    
  •      {     
  •          HttpServletRequest request=ServletActionContext.getRequest();    
  •          HttpSession session=request.getSession();    
  • //通过session 判断用户是否登录
  • if(session!=null && session.getAttribute("user")!=null) {    
  • return invocation.invoke();    
  •           }    
  • //设置客户原来请求的url地址  
  •          session.setAttribute("url", getGoingURL(request)); 
  • return Action.LOGIN;    
  •      }    
  • private String getGoingURL(HttpServletRequest request)    
  •      {     
  •          String url=request.getHeader("Referer");    
  • if(url==null || url.equals(""))    
  •          {    
  • //如果请求的是ACTION 则通过该代码获取URL地址,当然可以完善其功能
  •              url = request.getContextPath()+request.getServletPath()+"?"+request.getQueryString(); 
  •          }    
  • return url; 
  •      } 
  • 参考于:http://blog.csdn.net/oyjqdlp364356378/article/details/5715227
  • 你可能感兴趣的:(如何在struts2中登录后跳转到前置页面)