File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "sendRedirect problem " Watch "sendRedirect problem " New topic

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:

but it is coming as:

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");

will map to

will map to
I agree. Here's the link:
subject: sendRedirect problem
It's not a secret anymore!