Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

session variable

 
ajithsasi kumar
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to access a session variable in servlet from a jsp
 
Seetharaman Venkatasamy
Ranch Hand
Posts: 5575
Eclipse IDE Java Windows XP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi ajithsasi kumar,

You can access session variable from any component of your application..

in jsp just set the value & in servlet get the value
---------------------------------------
jsp:

session.setAttribute("key","value");//session is an implicit Object in jsp

servlet:

HttpSession session=request.getSession(false);
session.getAttribute("key");//returns Object value
---------------------------------------------

Thanks & regards,
seetharaman
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you want to access a session variable from JSP or from a servlet ?
 
sudhir nim
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And dont forget to set session attrtibute of page directive :0)

<%@page ... session="true" ..%>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ajithsasi kumar:
how to access a session variable in servlet from a jsp


 
Bosun Bello
Ranch Hand
Posts: 1511
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This happens to be the default value of this attribute. So it's not necessary to set it, unless if the page should not be part of the session, then it needs to b set to false.

Originally posted by sudhir:
And dont forget to set session attrtibute of page directive :0)

<%@page ... session="true" ..%>
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
"sudhir",
Please check your private messages regarding an important administrative matter.
-Ben
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varsha Garud,
Your post was moved to a new topic.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varsha Garud,
Your post was moved to a new topic.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65220
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Varsha Garud,
Your post was moved to a new topic.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic