FYI: Sessions with JSP without cookies

In case anyone is trying to use the URL-rewriting to
handle sessions for users without cookies, here's the
logic to do it. For each page, put this at the top:


// when this page is accessed for the first time,
redirect the
// user back to the page with the appropriate session
id appended
// (so that we can reference session variables from
here on in

   if (session.isNew())
      {
     
response.sendRedirect(response.encodeURL(request.getRequestURI()));

      // could use HttpUtils.getRequestURL(request) in
place of
      // request.getRequestURI() if needed
      }

For each reference within the page, you'll need a
response.encodeURL() call as well. For example, if you
want to reference the fred.html page inside your page,
you'd put:
    <a href="<%= response.encodeURL("fred.html")
%>">Fred's page</a>

You need to do this for *every* page and *every*
reference, but it works. Note that Jigsaw 2.1.2 isn't
compliant with the latest JSP specs, which require the
session variable to be JSESSION, I believe.

It feels nice when things work, doesn't it?

Mark


__________________________________________________
Do You Yahoo!?
Yahoo! Shopping - Thousands of Stores. Millions of Products.
http://shopping.yahoo.com/

Received on Friday, 8 December 2000 19:21:37 UTC