How can I access the HttpSession ? ? (For user role control)

I want to add check which user is working now.
To do this I am planning to check the users name first and add this name into the HttpSession so that I can access it from anywhere.
But since pageContext in JspTag is private, I can not access the session.
Can anybody tell me another way to implement this ?

Many thanks…

X-Application Version: 3.1.2
Tamino Version : 3.1.1
Platform : Win2k,
WebContainer : Tomcat 3.3
JDK Version : 1.3.1

It depends on where you place your code:

if you place it on the Jsp page itself
(using <% … %> ), you have access to
Jsp’s pageContext variable and you can
use pageContext.getSession()

if you place it in your own Jsp tag (which
is not derived from X-Application’s
JspTag class), you will implement the
setPageContext method (or derive it from

if you place it in your own Jsp tag (which
is derived from X-Application’s JspTag),
you have to overwrite JspTag.setPageContext()
in your tag. Basically, your method
“YourTag.setPageContext()” should store
the pageContext in a field of your class and
call the overridden method:
yourPageContextField = pageContext;
Now, you can use “yourPagecontextField”
to access the pageContext.
IMPORTANT: this solution is kind of a hack!
JspTag has a private pageContext field on
we want to run Unit tests on tags derived
from JspTag - but the pageContext is not
available in unit tests (since instances of
PageContext are created by Tomcat)
By isolating all access to the pageContext
in the JspTag class, we can fake the
information taken from pageContext and
run unit-test our tage without running Tomcat.
Overwriting setPageContext would violate
this policy …


Software AG Germany, Darmstadt

X-Application Version: 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1
X-Application Version: 3.1.2, 3.1.1
Tamino Version : 3.1.1
Platform : NT, Win2k, Solaris, …
WebContainer : Tomcat 3.3
JDK Version : 1.3.1

I prefer using the 3rd method in which I use a Tag derived from JspTag because I also need to access the Xapplication data.
But I didn’t understand what you mean by “Unit Tests”.
Will overriding the setPageContext method cause any problems in my application?
Is it possible that you might make this method private in further versions? (which will make my Tag useless since I can not access the PageContext)

Unit testing means “testing in isolation”: we
want to test our tags without running Tomcat.
Unit testing is a kind of buzz word and JUnit
is the most widespread tool for Java:

Overriding setPageContext doesn’t break
anything as long as you don’t want to run Unit
test for your tag.

The setPageContext method will never be
private (since the Tag interface requires a
public method).


Software AG Germany, Darmstadt

I’m using a session variable created like this:

<jsp:useBean id=“logon” scope=“session” class=“logonbean.Logon” />

But after have viewed a page with X-Application’s JspTags it seams my session variables are lost!

Can anyone tell me why?:confused:




normally X-Application does not modify the standard Session Object provided by Tomcat. X-Application uses this object to add its ServletSessionContext object. But it does not remove other objects stored within this session object.

To analyze your problem it would be helpful to have the jsp pages where you invoke the Bean and where you use the X-Application tags.

Please, describe also the order how the pages are invoked.

Thank you,
bye Christian.