I have a servlet code which invokes a stateful session bean code and increment an int value of it. But, when I am invoking the servlet and it's corresponding bean for the next time , the bean losses it's state and again starts from begining of incrementing. Can anybody help me how to solve this issue. My code is below:
public class CounterServlet extends HttpServlet {
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
try {
Counter counter = new Counter() ;
HttpSession clientSession = request.getSession(true);
clientSession.setAttribute("myStatefulBean", counter);
counter.increment() ;
// go to a jsp page
} catch (Exception e) {
out.close();
}
}
}