16.What is the difference between sendRedirect()and forward()in JSP?

In an HttpServletResponse class:

Response.sendRedirect () This function is used, when we want to redirect
the client request to some other site (i.e out of our context) or
when ever we want to redirect errors. If you are using sendRedirect (), then it will be visible to the client that means the URL which you have been redirected will be visible in the address bar. Redirect response to the client using the specified redirect location URL.

RequestDispatcher Interface:
Forward() : This can be done in two ways by Request & ServeletContext.
Forwarding a request from a servlet to another resource (servlet, JSP
file, or HTML file) on the server. Forward is done at server side, without the client’s knowledge.

When you invoke a forward request, the request is sent to another
resource on the server, without the client being informed that a
different resource is going to process the request. This process occurs
completely with in the web container. When a sendRedirtect method is
invoked, it causes the web container to return to the browser indicating
that a new URL should be requested. Because the browser issues a
completely new request any object that are stored as request attributes
before the redirect occurs will be lost. This extra round trip a
redirect is slower than forward.

Advertisements

3 Responses

  1. The Digfference between Forwarde and SendRedirect is

    1. The forward is used to forward the request to one page to another during run time.

    2.the redirect application it it redirects application to the another page . for eg we will consider gmail it redirects google web page…

  2. sdddas asd dasd

  3. This is very nice and informative post. I have bookmarked your site in order to find out your post in the future.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: