• Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Dax Joshi
Greenhorn
Posts: 14
Hibernate Java Spring
  • Mark post as helpful
  • send pies
  • 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 ?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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
 
Anindya Roy
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • 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 Java Spring
  • Mark post as helpful
  • send pies
  • 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.
 
Deepakkumar Devarajan
Ranch Hand
Posts: 54
Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!