Domanda

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?

È stato utile?

Soluzione 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.

Altri suggerimenti

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);

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top