File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes session variable Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "session variable" Watch "session variable" New topic
Author

session variable

ajithsasi kumar
Greenhorn

Joined: Apr 06, 2008
Posts: 21
how to access a session variable in servlet from a jsp
Seetharaman Venkatasamy
Ranch Hand

Joined: Jan 28, 2008
Posts: 5575

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

Joined: Nov 24, 2005
Posts: 14688
    
  16

Do you want to access a session variable from JSP or from a servlet ?


[My Blog]
All roads lead to JavaRanch
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

And dont forget to set session attrtibute of page directive :0)

<%@page ... session="true" ..%>


[Servlet tutorial] [Servlet 3.0 Cook Book]
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by ajithsasi kumar:
how to access a session variable in servlet from a jsp




Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bosun Bello
Ranch Hand

Joined: Nov 06, 2000
Posts: 1510
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" ..%>


Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

"sudhir",
Please check your private messages regarding an important administrative matter.
-Ben
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Varsha Garud,
Your post was moved to a new topic.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Varsha Garud,
Your post was moved to a new topic.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61606
    
  67

Varsha Garud,
Your post was moved to a new topic.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: session variable