1

I am a newbie in programming and I was just wondering how you can retrieve a session and show it's contents in the jsp page? And i'm coding it in java. Thanks for your help.

user3418987
  • 137
  • 2
  • 7
  • 16

4 Answers4

2
session.getAttribute("attributeName")

Try look here: How to use session in jsp pages to get information?

And try to google it more next time. I typed "java jsp get session" and it gave me the link above.

Community
  • 1
  • 1
StaNov
  • 332
  • 1
  • 4
  • 17
1

JSP holds implicit objects, where you can get the values from session.

Some of the methods of that are

Methods of session object:

setAttribute(String, object)
getAttribute(String name)
getAttributeNames
isNew()
getCreationTime
getId
invalidate()
getLastAccessedTime
getMaxInactiveInterval
removeAttribute(String name)

reference link

Vinay Veluri
  • 6,671
  • 5
  • 32
  • 56
1

jsp has implicit object called session you can directly use session object in scriplet or in expression in jsp as:

<%
String name = (String) session.setAttribute("attribute_name");
%>
Shekhar Khairnar
  • 2,643
  • 3
  • 26
  • 44
1

Take a look here:

JSP Tutorial

You can take data from a session in this way:

String name = request.getParameter( "username" );

and also add easily:

session.setAttribute( "theName", name );
ruhungry
  • 4,506
  • 20
  • 54
  • 98