wood burning stoves 2.0*
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


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "How do u use session in taglib" Watch "How do u use session in taglib" New topic
Author

How do u use session in taglib

Vadivel S
Greenhorn

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
Vadivel
Frank Carver
Sheriff

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 http://www.javaranch.com/name.jsp . 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.
Thanks.


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

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:
pageContext.getSession()
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
------------------
Adam Chace
Author of :JSP Tag Library


Adam Chace<BR>Author of :<A HREF="http://www.amazon.com/exec/obidos/ASIN/193011009X/electricporkchop/102-2552103-3190518" TARGET=_blank rel="nofollow">JSP Tag Libraries</A><BR><A HREF="http://www.chalkcreek.com" TARGET=_blank rel="nofollow">Chalk Creek Software</A>
Vadivel S
Greenhorn

Joined: May 26, 2001
Posts: 4
Hi,
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?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: How do u use session in taglib