David V�squez Estrada wrote:

> 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
> [...]

Hi:-)  I am not sure, I found:
- when cookie is enabled, HttpSession will "Prefer" to use cookie than
URL-rewriting  to save JSESSIONID(name/value="JSESSIONID"/"B730C71....")

- if cookie is disabled, then HttpSession will use URL-rewriting to save
  JSESSIONID, but now First you need to:
  % use HttpServletResponse.encodeURL/encodeRedirectURL
      to put the JSESSIONID in the URL which you want to give to client,
      otherwise you will still give your client a URL without JSESSIONID,
      and perhaps you will get a new session everytime.

  % and give this "encoded URL" to your client and "ask hime/her to click it :-)",
       or sendRedirect(...) it , or ...

  now your client "have joined the session"

 . for example:

  before encodeURL:
  http://x.x.x.x.:8080/mywebapp/servlet/TestSession

  after encodeURL:

http://x.x.x.x.:8080/mywebapp/servlet/TestSession;jsessionid=238490639024620774F141A4B1228534



- the following is a good email from List.this   :-)

...
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class TestSession extends HttpServlet {
   public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
      response.setContentType("text/html");
      PrintWriter pw = response.getWriter();
      HttpSession session=request.getSession();
      pw.println("<p>Session is new : " + session.isNew());
      pw.println("<p>Session ID : " + session.getId());
      pw.println("<p>Session is from cookie : " +
request.isRequestedSessionIdFromCookie());
      pw.println("<p>Session is from URL :    " +
request.isRequestedSessionIdFromURL());
      pw.println("<p><a href='" + response.encodeURL("TestSession") + "'New
request</a>");
  }
}


Try this servlet with as many browsers you can, with
cookies enabled and disabled. Observe not only the page
displayed, but also the address field in
the browser window. Everyhing will become clear !

Pierre-Yves



Bo
May.17, 2001

___________________________________________________________________________
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

Reply via email to