File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

sendRedirect problem

 
Micheal John
Ranch Hand
Posts: 344
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a doubt in HFSJ about sendDerirect's relative path:

My Folder structure


from servlet, I am using the below to different sendRedirect with relative URLs

1. response.sendRedirect("images/taiwan2.gif"); // Working as per the book

2. response.sendRedirect("/images/taiwan2.gif"); // NOT WORKING

As per the book the second case should come as:
http://localhost:8080/SCWCD/images/taiwan2.gif

but it is coming as:
http://localhost:8080/images/taiwan2.gif

Why? can anyone explain it?
 
Sreeraj G Harilal
Ranch Hand
Posts: 310
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
response.sendRedirect(String URL) method sends 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.
 
Gowher Naik
Ranch Hand
Posts: 643
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dont use response.sendRedirect("/images/taiwan2.gif");
use response.sendRedirect("/SCWCD/images/taiwan2.gif");

response.sendRedirect("images/taiwan2.gif");
will map to
http://localhost:8080/SCWCD/images/taiwan2.gif

response.sendRedirect("/SCWCD/images/taiwan2.gif");
will map to
http://localhost:8080/SCWCD/images/taiwan2.gif
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic