Suhail Gupta
Suhail Gupta

Reputation: 23206

why the url in the browser doesn't change when the request is forwarded to another page?

This is a small jsp page :

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page errorPage="errorpage.jsp" %>
<html tags>
<%-- about to be bad ! --%>
<% int x = 10/0; %>
</html tags>

The above page receives request from a servlet named FooServlet.(whose job is only to call the above jsp page). As soon as the servlet starts i see the default error page with it's message. But the url in the browser is same as that of the servlet. Why is it so ? Like the url of the error page is still http://localhost:8080/WebTesters/FooServlet.

Upvotes: 1

Views: 1413

Answers (4)

Aashutosh Shrivastava
Aashutosh Shrivastava

Reputation: 399

In case of Request Dispatcher request is not return to browser & it directly forward to page(servlet) from current servlet(page). So the browser url is not change. While in case of Send Redirect first request is return to browser from current page(servlet) & then forward to the specified(page). So the url is change.

Upvotes: 0

sasi
sasi

Reputation: 4318

In sendRedirection the request url will be changed,example:www.sun.com(for java) gives us www.oracle.com.but in forwarding or including mechanism the url dont shows the requested resource.

cause is when forwarding/including takes place the requested resource is within the web container.

Upvotes: 0

kundan bora
kundan bora

Reputation: 3889

Because this is request forwarding not request redirect. New Request only be made in request redirect.

Upvotes: 1

Perception
Perception

Reputation: 80603

Because this is part of the specification of how request forwarding works. A forward routes the request to the alternate resource via the server, which acts as a proxy between the client and the alternate resource.

This is different from a redirect, where the URL of the alternate resource is sent to the client as a header field, and the client is responsible for making a followup call to retrieve the alternate resource.

Upvotes: 4

Related Questions