/**
* 是否是Ajax异步请求
*
* @param request
*/
public static boolean isAjaxRequest(HttpServletRequest request) {
String accept = request.getHeader("accept");
if (accept != null && accept.indexOf("application/json") != -1) {
return true;
} String xRequestedWith = request.getHeader("X-Requested-With");
if (xRequestedWith != null && xRequestedWith.indexOf("XMLHttpRequest") != -1) {
return true;
} String uri = request.getRequestURI();
if (isContainStrs(uri, ".json", ".xml")) {
return true;
} String ajax = request.getParameter("__ajax");
if (isContainStrs(ajax, "json", "xml")) {
return true;
}
return false;
} public static boolean isContainStrs(String str, String... strs) {
if (str != null && strs != null) {
for (String s : strs) {
if (str.equalsIgnoreCase(trim(s))) {
return true;
}
}
}
return false;
} public static String trim(String str) {
return (str == null ? "" : str.trim());
}

最新文章

  1. 【新手学Python】一、基础篇
  2. 使用ExifInterface设置Datetime发生的问题
  3. Socket.IO – 基于 WebSocket 构建跨浏览器的实时应用
  4. nginx安装笔记
  5. 数据库分库分表中间件 Sharding-JDBC 源码分析 —— SQL 解析(四)之插入SQL
  6. Swift3中方法可变参数语法的一些改变
  7. 寻找春天 九宫格日记-2014.04.26
  8. HR在ERP实施过程中的作用
  9. JavaScript常见的代码精简
  10. golang struct tag
  11. Codeforces 791C. Bear and Different Names 模拟构造
  12. PFX文件提取公钥私钥
  13. Redis整体
  14. 实验二 C#程序设计 总结
  15. HDU - 5969 最大的位或 想法题
  16. 通过page页面与portlet的结合实现报表的局部刷新
  17. Linux ssldump命令
  18. Maven编译Java项目
  19. 当你用element-ui遇到需要在el-table-column上v-for时,这篇文章你能用的上,也就是你需要二级循环
  20. PTCRS 目前投资最成功的的PTC站点

热门文章

  1. Codeforces 1340F - Nastya and CBS(分块+哈希)
  2. 洛谷 P5644 - [PKUWC2018]猎人杀(分治+NTT)
  3. MYSQL5.8----M2
  4. Mysql查询优化汇总 order by优化例子,group by优化例子,limit优化例子,优化建议
  5. python 新闻管理系统——启示
  6. 45-Letter Combinations of a Phone Number
  7. k8s-hpa自动横向扩容
  8. 容器之分类与各种测试(三)——forward_list的用法
  9. Shell学习(九)——chattr与lsattr命令详解
  10. Linux学习 - 文件系统常用命令