0

Is it possible to retrieve session object stored by a servlet, in a JSP file? How do I do that?

Reporter
  • 3,897
  • 5
  • 33
  • 47
Arvind
  • 6,404
  • 20
  • 94
  • 143

4 Answers4

2

You can use EL ${} in JSP to access objects in page, request, session and application scope by their attribute name. You just have to specify the same name as you used in the servlet to store the attribute. For example, when you store an User object with the attribute name "user" as follows

request.getSession().setAttribute("user", user);

then it's available in the forwarded JSP by the same attribute name as follows

${user}

Another example if it has a name property with a getter:

<p>Welcome, <c:out value="${user.name}" /></p>

See also:

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
0

What handles the JSP? Anyway, if you use any more or less decent version of EL, you should be able to get it from EL via the implicit session object, like ${session.objectName}.

TC1
  • 1
  • 3
  • 20
  • 31
0

This post gives a rather comprehensive explanation of session access from JSPs and servlets.

Community
  • 1
  • 1
Dirk
  • 1,893
  • 1
  • 19
  • 26
0

Via EL: ${sessionScope.myObject}

atrain
  • 9,139
  • 1
  • 36
  • 40