This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android 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: 60785
    
  65

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: 60785
    
  65

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
 
Similar Threads
what if I add "encodeURL" to the action ?
Session management with cookies disabled client.
Getting Session as null
urgent - session null
listener question