There is a top-level folder help in the war file with index.html inside. What is the output of this code? (1 correct answer)
a.The content of index.html
b.HTTP Status 404
The answer given is b - status 404. But why should it fail?
As per my understanding, the war file would unfold to be the deployed application (directories and all). So wouldn't the container be able to find application_root/help/index.html?
Bear Bibeault wrote:Think about it for a minute. What issues the redirect? The server? The browser? Other?
Ummm.. a redirect is issued by the server to the browser? (redirecting to xyz Url)
According to the API, the server would convert the relative URL to absolute URL before sending the redirect back to the browser. So "/test/index.html" would become "http://www.example.com/myapp/test/index.html" . So still not sure why the browser would not find it?
Nidhi Sar wrote:Ummm.. a redirect is issued by the server to the browser? (redirecting to xyz Url)
So "/test/index.html" would become "http://www.example.com/myapp/test/index.html"
Hint: the redirect is asked for by the server, but is not issued by the server.
How does this change things?
I mean, won't the redirect request be changed to: http://www.example.com/help/index.html instead of http://www.example.com/myApp/help/index.html ?
Step 1. Client (browser) sends a request to resource X
Step 2. Resource X starts processing the request in a servlet and comes across response.sendDirect("resource Y").
Step 3. Resource X sends back a response to the client with a status code + some info, saying "go to resource Y"
Step 4. Client sends a new request to resource Y
/test/index.html would get converted to http://www.example.com/test/index.html (not with the app-directory in between as I wrote previously)
So the net result would be a new request from the client to http://www.example.com/test/index.html
Please correct me if I am wrong.
Does it have something to do with the 'servlet container root' instead of 'application root'?
I think whatever Pedro said is correct.
the response.sendRedirect() method expects its path parameter to be relative to the server root, not the webapp root. Thus, to send a redirect to the above URL from a servlet running , you must say
please ignore my earlier post.