I have following code segment in my servlet. Here, for some reason, I can not hold the session for the same user after creation of one session.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
response.setContentType("text/html");
PrintWriter writer = response.getWriter();
String userName = request.getParameter("userName");
HttpSession session = request.getSession();
if (userName != "" && userName != null) {
session.setAttribute("savedUserName", userName);
}
writer.println("Request parameter has user name as : " + userName + "<br />");
writer.println("Request session has user name as : " + (String) session.getAttribute("savedUserName") + "<br />");
}