我正在为我的 Web 应用程序使用 JQuery-Ajax 和 History.js,无论如何我可以确定请求是来自 AJAX 请求还是普通请求?我的目标是做这样的事情
<%if(isRequestAjax()){%>
<jsp:include page="/views/header.jsp" />
}
<%}%>
<div id ="profilePage>
<!-- user profile will be loaded here !-->
</div>
我也在使用 Struts2 和 MVC 框架
最佳答案
您必须检查请求 header X-Requested-With
它将是 XMLHttpRequest
if ("XMLHttpRequest".equals(req.getHeader("X-Requested-With")) ){
// include other file
}
关于java - JSP/Servlet如何识别HTTP请求是否来自ajax请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14004877/