Helpful Information
 
 
Category: Java Help
How to retrive a session value?

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

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/2.2/javadoc/index.html

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

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

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










privacy (GDPR)