I'm working with a HtppServlet and I need to use the session in order to know what I have to do (first time or not). But when I when the session it seems is always a different one, so the process always does the same it's supposed to do the first time. The code below:
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();
}
}
The thing is I need to call callMethod2()
the second time, but it's always calling callMethod1()
, I've tried using session.getSession(false)
and session.getSession()
I'm using curl to calling the Servlet and Google Chrome, does anyone have an idea what's happening or how can I solve this?