簡體   English   中英

JSP / Servlet如何識別HTTP請求是否來自ajax請求

[英]JSP/Servlet How to identify if the HTTP request came from an ajax request

我正在使用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框架

您必須檢查請求標頭X-Requested-With它將是XMLHttpRequest

  if ("XMLHttpRequest".equals(req.getHeader("X-Requested-With")) ){
           // include other file
  } 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM