encodeURL vs encodeRedirectURL

Discussions

Web tier: servlets, JSP, Web frameworks: encodeURL vs encodeRedirectURL

  1. encodeURL vs encodeRedirectURL (6 messages)

    Hi everyone.

    I cannot figure out what the difference between these 2 methods (response.encodeURL() and response.encodeRedirectURL). The Servlet API says that the encodeRedirectURL must ALWAYS be used within response.sendRedirect() commands. The reason it gives is as follows:

    "Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method."

    Can someone please explain what this really means? How do the rules differ for a redirect link?

    Thanks

    Paddy.
  2. encodeURL vs encodeRedirectURL[ Go to top ]

    sorry - my previous quote from the Sun Servlet API regarding the need for response.encodeRedirectURL() should hve read as follows:

    The implementation of this method includes the logic to determine whether the session ID needs to be encoded in the URL. Because the rules for making this determination can differ from those used to decide whether to encode a normal link, this method is seperate from the encodeURL method.
  3. Hi,
    encodeURL is used for all URLs in a servlet's output.
    It helps session ids to be encoded with the URL.

    encodeRedirectURL() is used with res.sendRedirect only.It is also used for encoding session ids with URL but only while redirecting.

    sankar.
  4. HiSankar.

    I agree with what you're saying, but you havene't explained the reasoning behind the need to ALWAYS use encodeRedirectURL() in a SendRedirect(), whereas we can use encodeURL() otherwise.

    Do you understand my question?

    Thanks

    Paddy
  5. encodeURL vs encodeRedirectURL[ Go to top ]

    both these methods revolve around the concept of URL rewriting. i dont know whether u r aware bout this. but basically it involves suffixing the URL with a HTTP_QUERY_STRING , which mostly is a session id used to keep track of a particular users context. URL re-writing is used get over the usage of cookies which are dependent on browser configuration, thus not reliable at all. now Session is a comprehensive topic on its own, so wont discuss it now.

    but yes the difference between the methods is in their usage and not their fuctionality. both perform the same task of re-writing a URL.

    us use encodeRedirectURL when u send a redirect header to the browser using response.sendRedirect(string URL)

    for eg lets say on a partucular condition u want to redirect to different page

    if (name == null){

    response.sendRedirect(response(encodeRedirectURL("errorPage.jsp"))
    }

    on the other hand lets say u wanna provide a link to shopping cart page to a user -

    printWriter.println("A HREF=" + response.encodeURL("shoppingCart.jasp") + ">")

    thus essentially they do same thing of re-writing the URl for non-cookie compliant browser.
  6. encodeURL vs encodeRedirectURL[ Go to top ]

    Hi Kapil

    Thanks for that - I understand the purpose of URL rewriting - but I'm still questioning why we have 2 seperate methods, and Sun's statement that the encodeRedirectURL() method does something different to the encodeURL() method.

    Paddy
  7. encodeURL vs encodeRedirectURL[ Go to top ]

    Hi,
    As far as i know encodeURL and encodeRedirectURL having diffrent feature.
    Just have a look at this.

    The encodeURL() method do more than just embed the session ID into the URL.

    1)It also rewrites URLs relative to the current document.if the url is not starting with http//.

    2)encodes any parameters added with the request.addQueryParameter or request.addURLParameter methods.

    Whereas encodeRedirectURL only encode the session ID associated with the realtice URL.