This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills: The software developer's life manual and have John Sonmez on-line!
See this thread for details.
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Servlet to servlet

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 642
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13044
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that both servlets need to be in the same "web application" or they can't share the session.
Bill
 
Don't get me started about those stupid light bulbs.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic