File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Servlets and the fly likes encodeURL methods Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "encodeURL methods" Watch "encodeURL methods" New topic
Author

encodeURL methods

emmanuel ramos
Greenhorn

Joined: Dec 21, 2011
Posts: 13
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
emmanuel ramos
Greenhorn

Joined: Dec 21, 2011
Posts: 13
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

Joined: Jan 10, 2002
Posts: 61764
    
  67

Have you checked the javadoc?
Vishal Shaw
Ranch Hand

Joined: Aug 09, 2012
Posts: 179
Hi,

Please check out this link

Regards,
Vishal


Programming is about thinking, NOT coding
emmanuel ramos
Greenhorn

Joined: Dec 21, 2011
Posts: 13
thank you very much is what I wanted



Vishal Shaw wrote:Hi,

Please check out this link

Regards,
Vishal
Ankush Kaundal
Ranch Hand

Joined: May 12, 2011
Posts: 36

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").
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: encodeURL methods