jsp - How to close a specific session in Java EE -


If I have multiple sessions open such that I can turn off a specific session:

 < Code> string user name = (string) session.getAttribute ("userName"); Hashmap Cartilist = (Hashmap) session.getAttribute ("cartList");   

What code should I use if I want to close the session with the cart?

I tried to use the following:

  1. session.invalidate () but it closes everything
  2. session.removeAttribute ("cartList"); This does not stop my session.

    You have several sessions open next to each visitor. You only have one session per visitor, you are simply storing the attributes in it "closing" is done by a session invalid () method, it destroys the entire session and eliminates all the attributes is. A new session will come as a result of any next HTTP request.

    You just want to open the shopping cart removeAttribute ("name") The method is the right thing to do. This will remove the attribute from the session, so that it is in the current response from getAttribute ("name") or $ {name} and all subsequent requests / reactions. This was apparently not working likely to have a false impression from your side.

    Also see:


Comments