Hi Joe, When you use URL rewritting for session tracking and you send a URL which references your site to the client, you will use these 2 methods. The difference between these 2 is: 1) You use "public String encodeURL(String url)" to the situation when the URLs are embedded in the web page that the servlet generates, eg. String oldURL = "/somepackage/someservlet1"; String newURL = response.encodedURL(oldURL); out.println("<A HREF=\"" + newURL + "\">go here</A>"); 2) You use public String encodeRedirectURL(String url) to the situation that you use a URL that refers to resource which you will use sendRedirect call. eg. String oldURL = "/somepackage/someservlet2"; String newURL = response.encodedRedirectURL(oldURL); response.sendRedirect(newURL);
Thanks for the answer. So you saying that encodeRedirectURL(String url) should always go together with sendRedirect(newURL)? I can't use for example: String oldURL="/String oldURL = "/somepackage/someservlet2"; String newURL = response.encodeURL(oldURL); response.sendRedirect(newURL);
Joined: Apr 26, 2002
You got it! Because All URLs sent to the HttpServletResponse.sendRedirect method should be run through the method public java.lang.String encodeRedirectURL(java.lang.String url).