This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Svelte and Sapper in Action and have Mark Volkmann on-line!
See this thread for details.
Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Confirmation required

 
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
 
Ranch Hand
Posts: 310
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.redirect("url")
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Was that a question or a statement?
 
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)
 
    Bookmark Topic Watch Topic
  • New Topic