超时下Ajax请求处理
来源:互联网 发布:剑网三的软件 编辑:程序博客网 时间:2024/05/13 19:00
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"); } } } });
0 0
- 超时下Ajax请求处理
- ajax请求超时处理
- session超时,处理ajax请求
- session超时,处理ajax请求
- session 超时,处理ajax请求
- ajax请求session 超时处理
- Ajax请求处理Session超时
- session超时,处理ajax请求
- mvc下ajax请求遇到session超时简单处理方式
- Ajax请求session超时处理流程
- Session超时后,Ajax请求处理方式
- Ajax请求Session超时的处理
- ajax异步请求,session超时处理
- ajax异步请求,session超时处理
- Session超时或无效,处理ajax请求
- Session超时后,Ajax请求处理方式
- Spring Security管理下的ajax请求登录超时问题处理
- Ajax请求超时问题
- 32位汇编语言学习笔记(43)-- 生成随机数
- Python 快速判断字符是否在字典元素都存在
- Bash For Loop Examples
- Python 评估字词在文件集的重要程度 (文档频率和逆向文档频率 TF-IDF)
- C++中cout输出字符型指针地址值的方法
- 超时下Ajax请求处理
- Topcoder SRM646 div1 600 bfs+剪枝
- 小波与滤波器组(4)
- 数组名和指针的区别
- Codefoeces 387E - George and Cards 贪心+线段树
- 使用 echo 列出当前位置的子目录
- hdu1269——迷宫城堡——————【双向并查集判断】
- 【BZOJ 1011】 [HNOI2008]遥远的行星
- POJ 3295 ——Tautology 枚举 构造 位运算可优化