On Wed, 30 Oct 2002, Monte Gardner wrote:

> I have a series of JSP pages that begin with a standard
> userid/password login.  The page that receives the login
> request (shop.jsp)  stores the id in the session like this
> session.setAttribute("id",id);
> when I print out
> session.getAttribute("id");
> on the same page, it prints the id of the user.  However, once the
> user goes to the next page where he views products, and I try to
> print out the user id with
> session.getAttribute("id") or
> request.getSession().getAttribute("id")
>
> It prints out null.  I have a previous project on the same server in
> which I did about the same thing, and it seems to work fine so I can't
> see what I'm doing different between the two.  What can cause the
> session to forget stuff like this?

Since HTTP is stateless, something actively needs to preserve the
session; for instance, a session identifier can be conveyed by a
cookie or as an addendum to the URL.

It's possible that your browser isn't sending cookies back to the
server; if it's not, and if you're not going out of your way to include
the session identifier in links back to your application, then the server
has no way of tying your multiple requests together into a session.

To ensure you support sessions for browsers that aren't using cookies,
make sure to encode the URL into all URLs that the application sends and
that also point back to the application.  The easiest way to ensure this
in a JSP page is by printing all URLs through JSTL's <c:url> tag.

--
Shawn Bayern
"JSTL in Action"   http://www.jstlbook.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:

 http://archives.java.sun.com/jsp-interest.html
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.jsp
 http://www.jguru.com/faq/index.jsp
 http://www.jspinsider.com

Reply via email to