I use jsp/Servlets for my web layer. Is there any tool to examine session attributes in a web session?
Which servlet container are you using? If it's JBoss, see this page.
Of course. It's not actually a tool, but a simple code snippet. Somewhere in a servlet/jsp/filter of yours add the following:
Session session = request.getSession();
Enumeration attributeNames = session.getAttributeNames();
while (attributeNames.hasMoreElements() {
String name = attributeNames.nextElement();
String value = session.getAttribute(name);
System.out.println(name + "=" + value);
}
and you will have all attributes of the session printed on the console.
Alternatively, in JSP do:
<c:forEach items="${sessionScope}" var="attr">
${attr.key}=${attr.value}<br>
</c:forEach>
this will print all attributes of the session on the page.
Update: It turns out you have a wrong understanding of the session. The session data is at the server-side. The client only hold a unique identifier by which its data is referred at the server. This identifier is most often the "session cookie", but can also be part of the url (JSESSIONID). So the client cannot see the contents of the session directly. If you want your session attributes to be displayed with meaninful values (different from their hashcode) override their toString()
method.