Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Any tool to view web session attributes? [closed]

I use jsp/Servlets for my web layer. Is there any tool to examine session attributes in a web session?

like image 219
ruwan.jayaweera Avatar asked Feb 03 '10 03:02

ruwan.jayaweera


People also ask

How to check session attributes in browser?

# View sessionStorage keys and valuesClick the Application tab to open the Application panel. Expand the Session Storage menu. Click a domain to view its key-value pairs. Click a row of the table to view the value in the viewer below the table.

What are session attributes?

A session attribute is a pre-defined variable that is persistent throughout the life of a Tealeaf session. Session attributes can be used to store various data that may be referenced by events at any point during the session.

What is @sessionattributes in Spring MVC?

@SessionAttribute annotation retrieve the existing attribute from the session. This annotation allows you to tell Spring which of your model attributes will also be copied to HttpSession before rendering the view.


1 Answers

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.

like image 91
Bozho Avatar answered Sep 28 '22 10:09

Bozho