if (req.getRequestURL() .toString() .contains("secondPage")) { writer.write("You are on the second page<br/>"); writer.write("myAttribute = " + req.getSession(false) .getAttribute("myAttribute"));
} else { HttpSession session = req.getSession(true); System.out.println("session id : " + session.getId()); session.setAttribute("myAttribute", "attrVal"); writer.write("<a href='" + req.getContextPath() + "/secondPage;jsessionid=" + session.getId() + "'>Visit the Second page</a>"); }