超时下Ajax请求处理
2015-01-17 08:20
211 查看
public class UserLogin extends HttpServlet { /** serialVersionUID */ private static final long serialVersionUID = 464654165487455L; /** * 这里只是示例代码,没有考虑代码的合理性: * * The doGet method of the servlet. <br> * This method is called when a form has its tag value method equals to get. * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // 如果是ajax请求,响应头会有x-requested-with相关字段信息 if (null == request.getSession().getAttribute("user")) { if (request.getHeader("x-requested-with") != null && request.getHeader("x-requested-with").equalsIgnoreCase("XMLHttpRequest")) { //在响应头设置session状态[可以在响应中自行添加相关字段信息] response.setHeader("sessionstatus", "nologin"); return; } } } /** * The doPost method of the servlet. <br> * * This method is called when a form has its tag value method equals to post. * * @param request the request send by the client to the server * @param response the response send by the server to the client * @throws ServletException if an error occurred * @throws IOException if an error occurred */ public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } }
$.ajaxSetup({ contentType:"application/x-www-form-urlencoded;charset=utf-8", complete:function(XMLHttpRequest,textStatus){ //通过XMLHttpRequest取得响应头,sessionstatus, var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); if(sessionstatus=="nologin"){ //如果超时就处理 ,指定要跳转的页面 window.location.replace("${path}/common/login.do"); } } } });
相关文章推荐
- Ajax请求session超时处理流程(DWZ)
- Ajax请求处理Session超时
- Session超时或无效,处理ajax请求
- Session超时后,Ajax请求处理方式
- spring security:ajax请求的session超时处理
- session 超时,处理ajax请求
- Ajax请求Session超时的处理
- Shiro 处理ajax请求 拦截登录超时 解决!
- ajax请求超时处理
- Extjs6关于Ajax和form表单提交以及store请求session超时的处理方法
- DWZ(JUI) 教程 Ajax请求session超时处理流程
- ajax异步请求,session超时处理
- web 会话超时,请求(http请求和ajax异步请求)处理
- 在Ajax请求中处理登录session超时的方法
- session超时,处理ajax请求
- Ajax请求Session超时的处理
- Spring Security管理下的ajax请求登录超时问题处理
- 利用setTimeoutc处理javascript ajax请求超时
- DWZ框架Ajax请求session超时处理
- mvc下ajax请求遇到session超时简单处理方式