Win a copy of Getting started with Java programming language this week in the Beginning Java forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Session Servlet to servlet  RSS feed

 
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: 643
  • 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: 13078
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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!