The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> Java Help
|
How to retrive a session value?
Discuss How to retrive a session value? in the Java Help forum on Dev Shed. How to retrive a session value? Java Help forum discussing all Java platforms - J2ME, J2SE and J2EE - as well as relevant standards, APIs and frameworks such as Swing, Servlets, JSPs, Applets, Struts, Spring, Hibernate, ANT, EJB, and other Java-related topics.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

April 23rd, 2001, 04:38 AM
|
 |
.Net Developer
|
|
Join Date: Feb 2000
Location: London
Posts: 987
Time spent in forums: 3 h 26 m 22 sec
Reputation Power: 14
|
|
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
|

April 23rd, 2001, 06:57 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: Helsinki, Finland
Posts: 1
Time spent in forums: < 1 sec
Reputation 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/2.2/javadoc/index.html
|

April 23rd, 2001, 12:30 PM
|
|
Junior Member
|
|
Join Date: Mar 2001
Location: surat
Posts: 0
Time spent in forums: < 1 sec
Reputation 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
|

April 24th, 2001, 04:06 AM
|
|
Junior Member
|
|
Join Date: Apr 2001
Location: Helsinki, Finland
Posts: 1
Time spent in forums: < 1 sec
Reputation 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...).
|

April 24th, 2001, 09:02 AM
|
|
Junior Member
|
|
Join Date: Mar 2001
Location: surat
Posts: 0
Time spent in forums: < 1 sec
Reputation 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
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|