Question

I know you can set and remove attributes from the java application using:

request.getSession().setAttribute("name",name);
request.getSession.removeAttribute("name");

I'm looking for a simple way to remove all attributes from a session when the user logs out, is there any one line command? or do I have to use removeAttribute() method for each of them?

Was it helpful?

Solution 2

On logout, you should be invalidating the user session, therefore, clearing up the user attributes. That way you don't have any application attributes.

OTHER TIPS

You have to use removeAttribute() for each of them. Note that there is no removeAll() or similar method in the Javadocs for HttpSession.

Your best bet is to get an Enumeration<String> of all attribute names with the getAttributeNames() method, then iterate over each one and manually calling removeAttribute().

Try session.setMaxInactiveInterval(0);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top