【发布时间】:2016-09-26 17:06:09
【问题描述】:
我正在使用 HtppServlet,我需要使用会话才能知道我必须做什么(第一次与否)。但是当我在会话时,它似乎总是一个不同的,所以这个过程总是做同样的事情,它应该是第一次做的。下面的代码:
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
HttpSession session = request.getSession(true);
response.setContentType("application/json");
PrintWriter out = response.getWriter();
try {
if (session.isNew()) {
String id=callMethod1();
session.setAttribute("ID",id);
} else {
callMethod2(session.getAttribute("ID"));
}
}catch (Exception ex) {
//Error handler
} finally {
out.close();
}
}
问题是我需要第二次调用callMethod2(),但它总是调用callMethod1(),我尝试使用session.getSession(false) 和session.getSession() 我正在使用curl 调用Servlet 和Google Chrome,有谁知道发生了什么或者我该如何解决这个问题?
【问题讨论】:
标签: session servlets httpsession