top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

How do you share session objects between servlets and JSP?

+3 votes
461 views
How do you share session objects between servlets and JSP?
posted Oct 15, 2015 by Shyam

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

+1 vote

Sharing sessions between a servlet and a JSP page is straight forward. JSP makes it a little easy by creating a session object and making it availabe already. In a servlet you would have to do it yourself. This is how:

//create a session if one is not created already now
HttpSession session = request.getSession(true);
//assign the session variable to a value.
session.putValue("variable","value");
in the jsp page this is how you get the session value:
<%
session.getValue("varible");
%>
answer Oct 16, 2015 by Karthick.c
...