判断一个请求是否是ajax
发布时间:2020-12-16 00:28:05 所属栏目:百科 来源:网络整理
导读:/** * Prepare a request,including setting the encoding and locale. * * @param request The request * @param response The response */ public void prepare(HttpServletRequest request,HttpServletResponse response) { String encoding = null; if (
/** * Prepare a request,including setting the encoding and locale. * * @param request The request * @param response The response */ public void prepare(HttpServletRequest request,HttpServletResponse response) { String encoding = null; if (defaultEncoding != null) { encoding = defaultEncoding; } // check for Ajax request to use UTF-8 encoding strictly http://www.w3.org/TR/XMLHttpRequest/#the-send-method <strong><span style="font-size:18px;">if ("XMLHttpRequest".equals(request.getHeader("X-Requested-With"))) { encoding = "UTF-8"; }</span></strong> Locale locale = null; if (defaultLocale != null) { locale = LocalizedTextUtil.localeFromString(defaultLocale,request.getLocale()); } if (encoding != null) { applyEncoding(request,encoding); } if (locale != null) { response.setLocale(locale); } if (paramsWorkaroundEnabled) { request.getParameter("foo"); // simply read any parameter (existing or not) to "prime" the request } }
注:request.getHeader("X-Requested-With") (request.getHeader中传递的参数,不区分大小写的) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |
相关内容
- Swift iOS EKEventStore:从EKEvent获取参加者有时会与NSIn
- c# – 单元测试异步方法
- rmarkdown ioslides:文件夹中的输出文件和其他文件夹中的依
- c# – 单击表单上的按钮时打开网站
- 内核kernel、根文件系统rootfs如何映射到对应的nand flash
- Cocos 2014开发者大会(秋季):刀塔传奇客户端技术分享/《
- C++入门笔记--神秘的家伙--this关键字的使用+继承
- nand flash otp(one time Programable)驱动编写细节
- 与XML Schema一起使用的表示法的名称
- ruby-on-rails – ActiveRecord create:传入一组属性