JSP::Confused with the session objects
Posted
by Legend
on Stack Overflow
See other posts from Stack Overflow
or by Legend
Published on 2010-06-15T21:01:07Z
Indexed on
2010/06/15
21:02 UTC
Read the original article
Hit count: 174
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.
© Stack Overflow or respective owner