This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
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


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: 641
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: 13000
    
    5
Note that both servlets need to be in the same "web application" or they can't share the session.
Bill
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Session Servlet to servlet
 
It's not a secret anymore!