#1
  1. .Net Developer
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2000
    Location
    London
    Posts
    987
    Rep Power
    15

    Question


    Hi,
    i created a session in servlet.but i don't know how it get that back.i created sesion like session.putValue("name","value"); ..session is creating successfully..please tell me how do i get that session value back.

    Thanks
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Helsinki, Finland
    Posts
    1
    Rep Power
    0
    Use session.getAttribute("name") to access it (as Object, so typecast).

    And don't use putValue(), it deprecated. Use setAttribute(name,value) instead.

    Good place for documentation
    http://java.sun.com/products/servlet...doc/index.html

    Comments on this post

    • JimmyGosling agrees
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    surat
    Posts
    0
    Rep Power
    0

    hi rajan


    Ok u created the session with session.putValue function now if u wann to get the values from the session then use this one:


    session.getValue("Session_name",value);

    this is one function what i m using for retrieving values from the session..... if u wann more then contact me

    bye

    Comments on this post

    • JimmyGosling agrees
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2001
    Location
    Helsinki, Finland
    Posts
    1
    Rep Power
    0
    Hmm... i don't think there's such method, getValue("name",value). It's getValue("name") and it returns an object.

    And those two (set/getValue) are deprecated so don't use those. Use set/getAttribute instead (assuming you have 2.2 sdk...).
  8. #5
  9. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2001
    Location
    surat
    Posts
    0
    Rep Power
    0

    Check this fae


    There is something wrong with that code what i wrote.

    But actually this is right way to get the session values from the session:


    here is first jst getting the object from session:

    public Object HttpSession.getValue(String name) here is class and code for this is here:

    String name = (String)session.getValue("Session id");

    and if u wann to get the all elements from the session that u put before then try this:

    String[] values = session.getValueNames();
    for (int i=0; i<values.length; i++) {

    out.println(values[i] + ": " +session.getValue(values[i]));
    }


    Check work or not

IMN logo majestic logo threadwatch logo seochat tools logo