0

Hi,
I have a problem related to Java servlet sessions. I don't understand why the getAttribute() function of the session object is used before setAttribute(); Here is the code:

Vector buylist=(Vector)session.getAttribute("Register");
if (action.equals("del")) {
        String del = request.getParameter("deli");
        int d = (new Integer(del)).intValue();
        buylist.removeElementAt(d);
      }
session.setAttribute("Register", buylist);

Thanks.

Edited by peter_budo: Keep It Clear - Do wrap your programming code blocks within [code] ... [/code] tags

3
Contributors
2
Replies
4
Views
6 Years
Discussion Span
Last Post by mKorbel
0

Probably doesn't want to create a new one if one already exists. But, in that case it has still been done wrongly, and there is no reason to have to place it back into the session, unless it is null after the get call, in which case it should be created an immediately placed into the session attritube. i.e.

ArrayList<String> bogus = session.getAttribute("bogus");
if (bogus == null) {
  bogus = new ArrayList<String>();
  session.putAttribute("bogus", bogus);
}
// do whatever you want with bogus except redefining it
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.