Dmitry Melekhov wrote:

> > Use HttpSession req.getSession(boolean), together with HttpSession.isNew()
> > etc. Read servlet API also :-)
>
> Hmm. I read it:
>
> public abstract HttpSession getSession(boolean create)
>
> Gets the current valid session associated with this request, if create is
> false or, if necessary, creates a new session for the request, if create is
> true.
>
> Question is how to say it to create session id in url, not a coockie?
>
> > >How can I  set session tracking to use session id in url?
> > >
>
> Dmitry Melekhov
> (aka 2:5050/11.23@fidonet)
> http://www.aspec.ru/~dm
>

The session creation stuff (shown above) is the same with or without cookies.
In fact, the servlet engine will always send the cookie the first time, to see
if the client returns it.

To ensure that session identity is passed even when cookies are turned off, you
have to call the encodeUrl() method every place you are generating a hyperlink
that points back to this server.  For example, if your servlet is generating a
link back to your main menu (at "menu.html") you need to do something like
this:

    PrintWriter pw = response.getWriter();
    ... other output stuff ...
    writer.println("Go to the <a href=\"" + response.encodeUrl("menu.html") +
"\">Main Menu</a>");
    ... other output stuff ...

There is also a special version of this -- encodeRedirectUrl() -- for when you
are creating URLs for a sendRedirect() call.  It's differeent because the rules
under which the session id suffix is required are slightly different.

Craig McClanahan




-- --------------------------------------------------------------
To subscribe:        [EMAIL PROTECTED]
To unsubscribe:      [EMAIL PROTECTED]
READ THE FAQ!!!!     <http://java.apache.org/faq/>
Archives and Other:  <http://java.apache.org/main/mail.html/>
Problems?:           [EMAIL PROTECTED]

Reply via email to