• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Difference between encodeURL() and encodeRedirectURL() method of response object

 
Greenhorn
Posts: 14
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference in working of encodeURL(String url) and encodeRedirectURL(String url) method HttpServletResponse class' object ?

In which different scenarios one should pick one ?
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Looking at the JavaDocs for the HttpServletResponse interface the specific difference is documented.

The encodeRedirectURL() method includes logic for handling a session ID.

The JavaDocs are your friend for questions like this.

Bill
 
Dax Joshi
Greenhorn
Posts: 14
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have gone through api doc. It seems very similar to me. I couldn't find out a liitle difference. Could you please elaborate.
Thanks.


William Brogden wrote:Looking at the JavaDocs for the HttpServletResponse interface the specific difference is documented.

The encodeRedirectURL() method includes logic for handling a session ID.

The JavaDocs are your friend for questions like this.

Bill

Screenshot-from-2014-07-03-09-22-37.png
[Thumbnail for Screenshot-from-2014-07-03-09-22-37.png]
javadoc of both method
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 response.sendRedirect only. It is also used for encoding session ids with URL but only while redirecting.
 
Dax Joshi
Greenhorn
Posts: 14
Hibernate Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think that both returns a string (url encoded with jsessionid, if required).

Returned value from any can be used with sendRedirect method.

then what's the major difference ?

Anindya Roy wrote:
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 response.sendRedirect only. It is also used for encoding session ids with URL but only while redirecting.

 
Ranch Hand
Posts: 54
Spring
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
encodeURL() method is used for normal links inside your html pages for e.g.

<a href="<%=response.encodeURL("/National/News.html")%>">New

encodeRedirectURL() is used for links send to response.sendRedirect().

Both these methods are declared in HttpResponse object.
 
Water! People swim in water! Even tiny ads swim in water:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic