Struts 通过拦截器实现登录后跳转到登录前页面 处理普通Http请求和Ajax请求时拦截配置
2015-04-17 16:12
1396 查看
<pre name="code" class="java"><pre name="code" class="java"> //登录 public void login() throws ViewException, IOException{ String message=userManager.loginByUser(userName, pwd, null); // request.setAttribute("prePage", prePage); //获取跳转到登陆界面之前的页面地址,由拦截器提供 prePage = (String) session.get("prePage"); //清除session中的数据 session.remove("prePage"); if (prePage == null) { //不是拦截器跳转到登陆页面的,直接访问的登陆页面 prePage="index"; } session.put("prePage", prePage); response.getWriter().print(message); }
//登录public void login() throws ViewException, IOException{String message=userManager.loginByUser(userName, pwd, null);// request.setAttribute("prePage", prePage); //获取跳转到登陆界面之前的页面地址,由拦截器提供 prePage = (String) session.get("prePage"); //清除session中的数据 session.remove("prePage");
if (prePage == null) { //不是拦截器跳转到登陆页面的,直接访问的登陆页面 prePage="index"; } session.put("prePage", prePage);response.getWriter().print(message);}
<pre name="code" class="html">
<interceptor name="userInterceptor" class="com.lyk.mooc.common.interceptor.UserLoginInterceptor" /> <interceptor-stack name="myStack"> <interceptor-ref name="createSession"></interceptor-ref> <interceptor-ref name="parameterFilter"> <param name="blocked">token,struts.token.name,struts.token</param> </interceptor-ref> <interceptor-ref name="defaultStack"></interceptor-ref> </interceptor-stack>
<global-results >
<result name="input" type="json"><param name="root">returnResult</param></result></global-results >
<action name="learnAction" class="learnAction" method="{1}"> <interceptor-ref name="userInterceptor"></interceptor-ref> <interceptor-ref name="myStack"></interceptor-ref> </action>
//异步请求,拦截的返回值(所有的json请求返回后执行的方法) $(document).ajaxComplete(function(event,xhr,settings){ if(xhr.responseText=='{"PERMISSION":"NO"}'){ //验证是否为登陆状态 window.location.href ="userAction!toLogin"; //跳转页面 } });
相关文章推荐
- 通过配置http拦截器,来进行ajax请求验证用户登录的页面跳转
- Struts2 拦截器处理普通Http请求和Ajax请求时拦截配置
- Struts2 拦截器处理普通Http请求和Ajax请求时拦截配置
- Struts2 拦截器处理普通Http请求和Ajax请求时拦截配置
- Struts2 拦截器处理同步(普通Http)请求和异步(post,ajax)请求时拦截配置
- Struts 拦截器权限控制【通过拦截器实现登录后跳转到登录前页面】
- ajax前置处理实现异步请求session过期时跳转登录页面
- Struts 拦截器权限控制【通过拦截器实现登录后跳转到登录前页面】
- Struts 拦截器权限控制【通过拦截器实现登录后跳转到登录前页面】
- Struts 拦截器权限控制【通过拦截器实现登录后跳转到登录前页面】
- Struts2通过自定义拦截器实现登录之后跳转到原页面
- 重写ajax方法实现异步请求session过期时跳转登录页面
- 重写ajax方法实现异步请求session过期时跳转登录页面
- Struts2通过自己定义拦截器实现登录之后跳转到原页面
- 重写ajax方法实现异步请求session过期时跳转登录页面
- 重写ajax方法实现异步请求session过期时跳转登录页面
- shiro 拦截器实现session过期拦截ajax请求的处理
- 处理jquery的ajax请求session过期跳转到登录页面
- 重写ajax方法实现请求session过期时跳转登录页面
- 重写ajax方法实现异步请求session过期时跳转登录页面(转)