• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Session Servlet to servlet

 
Sham Jowsaki
Ranch Hand
Posts: 146
  • 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
  • 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: 13061
6
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic