Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
The moose likes Servlets and the fly likes Session Servlet to servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Session Servlet to servlet" Watch "Session Servlet to servlet" New topic
Author

Session Servlet to servlet

Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi ALL,
I hv 2 servlets, creating a session in one servlet n need to call the session value in other second servlet.
it is workin out with getValue() n putValue().. can you pls provide me sample code.
tks
jowsaki
Praful Thakare
Ranch Hand

Joined: Feb 10, 2001
Posts: 627
HI,
Hope this helps u

Servlet_one.java
doPost(.....)
{
session.setAttribute("key","value");
.......
}
Servlet_two.java
dopost(...)
{
String val=(String) session.getAttribure("key");
}
getAttribute returns Object hence the cast!!!
regards
Praful


All desirable things in life are either illegal, banned, expensive or married to someone else !!!
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12769
    
    5
Note that both servlets need to be in the same "web application" or they can't share the session.
Bill
 
 
subject: Session Servlet to servlet