JAVA判断是否是Ajax请求
2024-10-16 22:54:17
/**
* 是否是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());
}
最新文章
- 【新手学Python】一、基础篇
- 使用ExifInterface设置Datetime发生的问题
- Socket.IO – 基于 WebSocket 构建跨浏览器的实时应用
- nginx安装笔记
- 数据库分库分表中间件 Sharding-JDBC 源码分析 —— SQL 解析(四)之插入SQL
- Swift3中方法可变参数语法的一些改变
- 寻找春天&;nbsp;九宫格日记-2014.04.26
- HR在ERP实施过程中的作用
- JavaScript常见的代码精简
- golang struct tag
- Codeforces 791C. Bear and Different Names 模拟构造
- PFX文件提取公钥私钥
- Redis整体
- 实验二 C#程序设计 总结
- HDU - 5969 最大的位或 想法题
- 通过page页面与portlet的结合实现报表的局部刷新
- Linux ssldump命令
- Maven编译Java项目
- 当你用element-ui遇到需要在el-table-column上v-for时,这篇文章你能用的上,也就是你需要二级循环
- PTCRS 目前投资最成功的的PTC站点
热门文章
- Codeforces 1340F - Nastya and CBS(分块+哈希)
- 洛谷 P5644 - [PKUWC2018]猎人杀(分治+NTT)
- MYSQL5.8----M2
- Mysql查询优化汇总 order by优化例子,group by优化例子,limit优化例子,优化建议
- python 新闻管理系统——启示
- 45-Letter Combinations of a Phone Number
- k8s-hpa自动横向扩容
- 容器之分类与各种测试(三)——forward_list的用法
- Shell学习(九)——chattr与lsattr命令详解
- Linux学习 - 文件系统常用命令