This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes session.getAttributeNames() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "session.getAttributeNames()" Watch "session.getAttributeNames()" New topic
Author

session.getAttributeNames()

chris
Greenhorn

Joined: Sep 28, 2007
Posts: 5
Hi all,
I was wondering if there is a way to get a list of attribute names of the session in a JSP page.

In a Servlet I would do this with the following code:

Enumeration e = session.getAttributeNames();
while (e.hasMoreElements()) {
String name = (String)e.nextElement();
String value = session.getAttribute(name).toString();
System.out.println("name is: " + name + " value is: " + value);
}

Is there a way to get the name and value pairs in JSP as well? If yes, could you please show the code?

Thanks
Chris
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

If you are writing old-fashioned JSP pages with scriplets, the same way.

If you're writing modern scriptless JSP pages, remember that the sessionScope implicit scoped variable is an implementation of a Map that you can iterate over. So...


[ October 01, 2007: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session.getAttributeNames()
 
Similar Threads
how to find total active session at the given moment
JSP behaving badly!
Is this an array?
Servlet sessions
Sessions... confused