File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes How do u use session in taglib Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do u use session in taglib" Watch "How do u use session in taglib" New topic

How do u use session in taglib

Vadivel S

Joined: May 26, 2001
Posts: 4
Hi friends,
How do i store my data in session from the java class in which i've implemented my tag logic.
For ex. My class Sample extends TagSupport
Will i be able to access session object from this class?
Thanks & Regards
Frank Carver

Joined: Jan 07, 1999
Posts: 6920
"Vadivel S",
The Java Ranch has thousands of visitors every week, many with surprisingly similar names. To avoid confusion we have a naming convention, described at . We require names to have at least two words, separated by a space, and strongly recommend that you use your full real name. Please log in with a new name which meets the requirements.

Read about me at ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Adam Chace

Joined: May 24, 2001
Posts: 14
From within a tag handler, you can access the session most easily through the methods of PageContext class. An instance of the PageContext class is available to you, if your handler extends TagSupport or BodyTagSupport, automatically as "pageContext". You can get the session directly by calling:
or you can get and set values to the session through the cleaner:
pageContext.getAttribute( "attributeName", PageContext.SESSION_SCOPE )
pageContext.setAttribute( "attributeName", value, PageContext.SESSION_SCOPE )
Hope this helps,
Adam Chace
Author of :JSP Tag Library

Adam Chace<BR>Author of :<A HREF="" TARGET=_blank rel="nofollow">JSP Tag Libraries</A><BR><A HREF="" TARGET=_blank rel="nofollow">Chalk Creek Software</A>
Vadivel S

Joined: May 26, 2001
Posts: 4
It's working fine and i was struggling with this problem for a week.
Actually I'm developing some custom tags to Connect, query and update the database.
I would like to have the resultset in some formatted data and cache it across the user session to avoid frequent database I/O.
Right now I'm storing the formatted data in session. By saying formatted data I mean, I have a class in which I store the data with some meta data.
If u have any suggestions please let me know.
Thanks & Regards
Vadivel S
[This message has been edited by Vadivel S (edited June 27, 2001).]
Cameron Park
Ranch Hand

Joined: Apr 06, 2001
Posts: 371
What is pageContext's equivalent in servlet, the servlet application's ServletContext, or a new thing with the page scope?
I agree. Here's the link:
subject: How do u use session in taglib
It's not a secret anymore!