You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Joel Regen <jo...@Globeset.com> on 2000/07/08 04:59:35 UTC

sessions and JSP Tag Handlers

Hello,

I am working on a product demo for a web-based payment collection service.  In
the demo, I am using the session to hold various objects.  For example, a
merchant id (ID) is stored in the session at the first request (in a jsp page).
This is done within a Tag Handler by accessing

             pageContext.getSession().setAttribute("merchantID", ID);.

I have discovered that this is not working as expected:  an attempt to access
ID:

            pageContext.getSession().getAttribute("merchantID");

from a different jsp page and a different tag handler yields a null value. I
assumed that the session object was maintained across pages by the JSP container
(tomcat) and that accessing it via the page context would work since, by
default, jsp pages participate in sessions.

What am I missing here?

I've looked at the source code: Tomcat is obtaining the session object from the
request, as expected, in PageContextImpl:
   ...
    if (request instanceof HttpServletRequest && needsSession)
        this.session = ((HttpServletRequest)request).getSession();
   ...

But the session is changing between pages as evidenced by log("session id is: "
+ session.getId()); calls on different pages.   This makes me suspect some sort
of problem with the request mechanism....I don't know...

I don't get it.


thanks,
Joel






Re: sessions and JSP Tag Handlers

Posted by Joel Regen <jo...@Globeset.com>.

Joel Regen wrote:

> Hello,
>
> I am working on a product demo for a web-based payment collection service.  In
> the demo, I am using the session to hold various objects.  For example, a
> merchant id (ID) is stored in the session at the first request (in a jsp page).
> This is done within a Tag Handler by accessing
>
>              pageContext.getSession().setAttribute("merchantID", ID);.
>
> I have discovered that this is not working as expected:  an attempt to access
> ID:
>
>             pageContext.getSession().getAttribute("merchantID");
>
> from a different jsp page and a different tag handler yields a null value. I
> assumed that the session object was maintained across pages by the JSP container
> (tomcat) and that accessing it via the page context would work since, by
> default, jsp pages participate in sessions.
>
> What am I missing here?
>
> I've looked at the source code: Tomcat is obtaining the session object from the
> request, as expected, in PageContextImpl:
>    ...
>     if (request instanceof HttpServletRequest && needsSession)
>         this.session = ((HttpServletRequest)request).getSession();
>    ...
>
> But the session is changing between pages as evidenced by log("session id is: "
> + session.getId()); calls on different pages.   This makes me suspect some sort
> of problem with the request mechanism....I don't know...
>
> I don't get it.
>
> thanks,
> Joel

additional information:
____________________________________________________________________
in server.xml:
        <RequestInterceptor className="org.apache.tomcat.request.SessionInterceptor"
debug="9"/>
____________________________________________________________________
in tomcat.log (from one request to select_instrument.jsp):
.....
 Orig sessionId  To1012mC8881234732891015At
 XXX RURI=/PCSDemo/select_instrument.jsp
createRequest /select_instrument.jsp /PCSDemo/select_instrument.jsp
 XXX RURI=/PCSDemo/select_instrument.jsp
Context log: path="/PCSDemo" Get real path /select_instrument.jsp
D:\dev\PCSDemo\jakarta-tomcat\webapps\PCSDemo\select_instrument.jsp
/select_instrument.jsp
createRequest /select_instrument.jsp /PCSDemo/select_instrument.jsp
 XXX RURI=/PCSDemo/select_instrument.jsp
Context log: path="/PCSDemo" Get real path \select_instrument.jsp
D:\dev\PCSDemo\jakarta-tomcat\webapps\PCSDemo\select_instrument.jsp
/select_instrument.jsp
createRequest /select_instrument.jsp /PCSDemo/select_instrument.jsp
 XXX RURI=/PCSDemo/select_instrument.jsp
Context log: path="/PCSDemo" Get real path \select_instrument.jsp
D:\dev\PCSDemo\jakarta-tomcat\webapps\PCSDemo\select_instrument.jsp
/select_instrument.jsp
createRequest /select_instrument.jsp /PCSDemo/select_instrument.jsp
 XXX RURI=/PCSDemo/select_instrument.jsp
Context log: path="/PCSDemo" Get real path \select_instrument.jsp
D:\dev\PCSDemo\jakarta-tomcat\webapps\PCSDemo\select_instrument.jsp
/select_instrument.jsp
createRequest /select_instrument.jsp /PCSDemo/select_instrument.jsp
 XXX RURI=/PCSDemo/select_instrument.jsp
Context log: path="/PCSDemo" Get real path \select_instrument.jsp
D:\dev\PCSDemo\jakarta-tomcat\webapps\PCSDemo\select_instrument.jsp
/select_instrument.jsp
Before Body To1010mC8882894419450669At
.....


Re: sessions and JSP Tag Handlers

Posted by "Craig R. McClanahan" <Cr...@eng.sun.com>.

Joel Regen wrote:

> I figured this out and it is kinda embarrasing.

We've all been there and done that!  :-)

>
> The reason, I suspect, that my session tracking was not working was that I was using
> localhost in a couple places in my code (jsp page and in initial url).
> That probably hoses anything to do with sessions across pages.
> for future reference anyway.   :-o
>

Sessions are "by definition" tied to a particular servlet context on a particular
hostname.  If you use relative hyperlinks, you don't generally have to worry about this,
because the browser reconstructs an absolute URL that includes the host name of the
server it got this page from.  But, "www.mycompany.com" and "localhost" are considered
to be different hosts, even if they are the same machine and resolve to the same
webserver.

>   _ _
>   o o
>     |
>    O
>
> Joel Regen wrote:
>

Craig McClanahan



Re: sessions and JSP Tag Handlers

Posted by Joel Regen <jo...@Globeset.com>.
I figured this out and it is kinda embarrasing.
The reason, I suspect, that my session tracking was not working was that I was using
localhost in a couple places in my code (jsp page and in initial url).
That probably hoses anything to do with sessions across pages.
for future reference anyway.   :-o
  _ _
  o o
    |
   O


Joel Regen wrote:

> Hello,
>
> I am working on a product demo for a web-based payment collection service.  In
> the demo, I am using the session to hold various objects.  For example, a
> merchant id (ID) is stored in the session at the first request (in a jsp page).
> This is done within a Tag Handler by accessing
>
>              pageContext.getSession().setAttribute("merchantID", ID);.
>
> I have discovered that this is not working as expected:  an attempt to access
> ID:
>
>             pageContext.getSession().getAttribute("merchantID");
>
> from a different jsp page and a different tag handler yields a null value. I
> assumed that the session object was maintained across pages by the JSP container
> (tomcat) and that accessing it via the page context would work since, by
> default, jsp pages participate in sessions.
>
> What am I missing here?
>
> I've looked at the source code: Tomcat is obtaining the session object from the
> request, as expected, in PageContextImpl:
>    ...
>     if (request instanceof HttpServletRequest && needsSession)
>         this.session = ((HttpServletRequest)request).getSession();
>    ...
>
> But the session is changing between pages as evidenced by log("session id is: "
> + session.getId()); calls on different pages.   This makes me suspect some sort
> of problem with the request mechanism....I don't know...
>
> I don't get it.
>
> thanks,
> Joel