For a servlet to support session tracking via URL rewriting, it
has to rewrite every local URL before sending it to the client.
The Servlet API provides two methods - encodeURL() and
encodeRedirectURL() - to perform this encoding:
public String HttpServletResponse.encodeURL( String url)
public String HttpServletResponse.encodeRedirectURL( String url)
The following code snippet shows a servlet writing a link to
itself that is encoded to contain the current session ID:
out.println( "Click <a href=\"" + res.encodeURL(
req.getRequestURI()) + "\">here</a>;
out.println( "to reload this page.");
On servers that don't support URL rewriting or have URL rewriting
turned off, the resulting URL remains unchanged.
For a servlet that redirects the user to a URL encoded to contain
a session ID:
res.sendRedirect( res.encodeRedirectURL( "/servlet/NewServlet"));
A servlet can detect whether the session ID used to identify the
current HttpSession object came from a cookie or from an encoded
URL using the isRequestedSessionIdFromCookie() and
isRequestSessionIdFromURL() mehods:
public boolean
HttpServletRequest.isRequestedSessionIdFromCookie()
public boolean
HttpServletRequest.isRequestedSessionIdFromURL()
Determining if the session ID came from another source, such as
an SSL session is not currently possible.
You can find code examples of these concepts in Jason Hunter's
"Java Servlet Programming, 2ed.," pp. 223ff.
Cheers!
Mark
----- Original Message -----
From: "David V�squez Estrada" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 17, 2001 9:24 AM
Subject: Re: Where is the session info?
> Hi,
>
> Can you explain me please a little bit more, with a sample
code, how to use the
> technique URL rewriting?
>
> Thanks in advance,
>
> David
>
>
_________________________________________________________________
__________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
>
_________________________________________________________________
__________
> To unsubscribe, send email to [EMAIL PROTECTED] and include
in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives:
http://archives.java.sun.com/archives/servlet-interest.html
> Resources:
http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html