Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Confirmation required

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if we have to encode redirect that doest not support cookies then below methods should be used.
response.encodeRedirectURL(response.redirect("url"));
Thanks
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.redirect("url")
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was that a question or a statement?
 
Siddharth Purandare
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gowher,

I will try my best to explain let me know whether you get it.

As per Head First URL re-writing is automatic ONLY if you encode your URL's through the 2 method of response object i.e
1. encodeURL(java.lang.String url) and
2. encodeRedirectURL(java.lang.String url)

rest of the things container will take care by itself. NOW the question is when to use which method??

the method encodeRedirectURL(java.lang.String url)
is used if:

All URLs sent to the HttpServletResponse.sendRedirect method should be run through encodeRedirectURL(java.lang.String url)

Next Doubt may come like what is sendRedirect so from the Java API here is the extract.

sendRedirect
public void sendRedirect(java.lang.String location)
throws java.io.IOExceptionSends a temporary redirect response to the client using the specified redirect location URL. This method can accept relative URLs; the servlet container must convert the relative URL to an absolute URL before sending the response to the client. If the location is relative without a leading '/' the container interprets it as relative to the current request URI. If the location is relative with a leading '/' the container interprets it as relative to the servlet container root.
If the response has already been committed, this method throws an IllegalStateException. After using this method, the response should be considered to be committed and should not be written to.

Parameters:
location - the redirect location URL
Throws:
java.io.IOException - If an input or output exception occurs
java.lang.IllegalStateException - If the response was committed


Hope you have understood.


So the final conclusion is YOU CANNOT USE response.encodeRedirectURL(response.redirect("url")); what you mentioned in the question!!!
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HFS&JSP pno-237 says
URL rewriting is automatic but only if you encode your URLs.You have to run all your URLs through a method ot the response object-encodeURL() or encodeRedirectURL()and the container does everything else.
I thing meaning of above statement is

encodeURL("url");
response.encodeRedirectURL(response.redirect("url"));

is it so?
 
Siddharth Purandare
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No Gowher the correct USAGE is

response.sendRedirect(response.encodeRedirectURL("/whateveryouwish.jsp"));

because response.encodeRedirectURL("/whateveryouwish.jsp") will return a String and sendRedirect() method accepts String signatures of the 2 methods are as below:

1. public void sendRedirect(java.lang.String location)
throws java.io.IOException

2. public java.lang.String encodeRedirectURL(java.lang.String url)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic