1. 程式人生 > >攔截ajax請求

攔截ajax請求

HttpServletResponse response = ServletActionContext.getResponse();

HttpServletRequest request= (HttpServletRequest) request;

PrintWriter out = response.getWriter();

先判斷session是否存在,也就是是否已經登入

沒有登入就判斷請求型別

if (request.getHeader("x-requested-with") != null

&& "XMLHttpRequest".equals(request.getHeader(

"x-requested-with"))) {

out .write("login");

}

然後在js中對返回返回值進行判斷