encodeURL and encodeRedirectURL

If the client doesn't accept cookies,we can use URL rewriting as a backup. URL rewriting will always work.URL rewriting takes the session ID that is in the cookie and sticks it right onto the end of every URL that comes in to this app.When the user clicks that "enhanced "link ,the request goes to the container with that extra bit on the end ,and the Container simply strips off the extra part of the request URL and uses it to find the matching session.URL rewriting kicks in only if cookies fail,and only if you  tell the response to encode the URL.If you want the container to always default to using cookies first,with URL rewriting only as a last resort.You should explicitly encode your URLs,and the client would accept cookies,you get to use sessions,and the container will first attempt to use cookies for session management.
You code should like :

HttpSession session = request.getSession();//Get a session.
out.println("<a href\""+response.encodeURL("/BeerTest.do")+"\">click me</a>"); //Add the extra session ID info to this URL.


You want to redirect the request to a different URL ,but you still want to use a session.There is a special URL encoding method just for that:

response.encodeRedirectURL("/BeerTest.do")

你可能感兴趣的:(encodeURL)