Вопрос

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?

Это было полезно?

Решение 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.

Другие советы

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

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top