How to list all session variables

I am working with a Java/JSP application someone else developed. How can I print a list of all session variables available to me?

I tried this:

Enumeration mySession = session.getAttributeNames();
while (mySession.hasMoreElements()) {
String mySessionVarName = (String)mySession.nextElement();
String myValue = (String)session.getValue(mySessionVarName);
out.println(mySessionVarName + “=” + myValue + “<br>”);
}

but I get error messages such as:
Error 500: java.util.Locale incompatible with java.lang.StringAny suggestions?

try the following


Enumeration keys = session.getAttributeNames();
while (keys.hasMoreElements())
{
  String key = (String)keys.nextElement();
  out.println(key + ": " + session.getValue(key) + "<br>");
}

You are trying to cast your value Object into a String. You don’t know what the true class of that value Object is. So you are getting a cast exception because the object you’re getting by a specific key is a Locale object instead of a String object.

Best of Luck.

Thanks! That did the trick.