Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

encodeURL methods

 
emmanuel ramos
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi All
I have a question about the encodeURL and encodeRedirectURL, what is the diference between them and why if I put


<a href="<% response.encodeURL("sessions.jsp"); %>">link</a>


why this link points to another direction that is not the JSP



 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't really know what you mean by that, but you shouldn't be using scriptlets in a JSP at all. You should be using the JSTL's <c:url> tag to create properly encoded URLs.

Please read this this JspFaq entry.
 
emmanuel ramos
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:I don't really know what you mean by that, but you shouldn't be using scriptlets in a JSP at all. You should be using the JSTL's <c:url> tag to create properly encoded URLs.

Please read this this JspFaq entry.




I'am reading the book "Head Firts in Servlets and JSP" and the book put this code


public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException {
response.setContentType(“text/html”);
PrintWriter out = response.getWriter();
HttpSession session = request.getSession();
out.println(“<html><body>”);
out.println(“click me”);
out.println(“</body></html>”);
}


and Say " if you
don’t explicitly encode your URLs, and the client won’t accept cookies,
you don’t get to use sessions. If you do encode your URLs, the Container
will first attempt to use cookies for session management, and fall back to URL
rewriting only if the cookie approach fails."


My question is what is the diference between response.encodeURL() and encodeRedirectURL(), because in the book are very similar this methods?


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64835
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you checked the javadoc?
 
Vishal Shaw
Ranch Hand
Posts: 179
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Please check out this link

Regards,
Vishal
 
emmanuel ramos
Greenhorn
Posts: 13
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you very much is what I wanted



Vishal Shaw wrote:Hi,

Please check out this link

Regards,
Vishal
 
Ankush Kaundal
Ranch Hand
Posts: 36
Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.encodeURL("somevalue") -> here encodeURL will add extra session ID info to the end of the URL.
but if you want to redirect to some other URL and still want to maintain session then use response.encodeRedirectURL("somevalue").
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic