JSP::Confused with the session objects
- by Legend
I just started exploring Java Servlets and JSP and am a little confused about the sessions object. Inside a servlet I have this:
public class SampleServlet extends HttpServlet {
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException {
HttpSession session = request.getSession(true);
session.setAttribute("_session", "_value");
response.sendRedirect("page2.jsp");
}
}
Now, inside page2.jsp, there is a session object as well, but when I do this
<%
out.print(session.getAttribute("_session"))
%>
it gives me an error. Can someone tell me the right way of doing this? As to what I am trying to do, I want to share some session variables.