2
我在通過ajax
cal調用servlet
中檢索會話屬性時遇到問題。無法從ajax調用servlet檢索會話屬性
$('#homemainSearchField').submit(function(){
$.get("./CheckNoOfSearch",function(data){
checkLimitation(data);
});
});
在CheckNoOfSearch
servlet
我試圖找回一些會話屬性,但所有的會話屬性爲空,但它不是,我沒有把它設置。
的servlet代碼是
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
HttpSession session = request.getSession();
int noOfSearch = 0;
if (session.getAttribute("auth") != null && session.getAttribute("type") != null) {
System.out.println("Session found");
}
out.print(noOfSearch);
} finally {
out.close();
}
}
向我們展示您的servlet代碼。你的問題在於servlet代碼。您正確使用$ .get。 – Funkytown