wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes sendRedirect problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendRedirect problem " Watch "sendRedirect problem " New topic
Author

sendRedirect problem

Micheal John
Ranch Hand

Joined: Nov 01, 2006
Posts: 344
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?


Micheal John
SCJP 1.4 (86%), SCWCD 1.4 (86%), SCBCD 1.3 (85%), SCDJWS (Just Started...) - Satisfaction Lies in Our EFFORT, Not in the ATTAINMENT
Sreeraj G Harilal
Ranch Hand

Joined: Apr 19, 2006
Posts: 310
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.


SCJP 5.0<br />SCWCD 1.4<br />Preparing for <b>SCEA</b>.<br /><b>"I prefer an interesting vice to a virtue that bores."</b>
Gowher Naik
Ranch Hand

Joined: Feb 07, 2005
Posts: 643
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.
 
subject: sendRedirect problem
 
Similar Threads
SCWCD
sendRedirect Problem
404 - Page not found ??
SCWCD
Getting absolute path of image file