answersLogoWhite

0

What is the difference between jsp forward and response sendRedirect?

Updated: 8/18/2019
User Avatar

Anandvijayakumar

Lvl 1
14y ago

Best Answer

The <jsp:forward ..> is actually a call to HttpServletRequest.forward(String url) which passes the request object within the server to either a servlet or to another JSP page. The new servlet or JSP page continues to process the same request and the browser is not aware of the fact that more than one servlet or page is involved. i.e., The client is not aware that the request is being forwarded somewhere else. The URL shown in the browser stays unchanged when you do this forward.

The <jsp:forward> element forwards the request object containing the client request information from one JSP file to another file. The target file can be an HTML file, another JSP file, or a servlet, as long as it is in the same application context as the forwarding JSP file. The lines in the source JSP file after the <jsp:forward> element are not processed.

The page invoked by the <jsp:forward> action has access to all the parameters in the original JSP page's request object. You can add new parameters to the request object to pass to the target page by using the <jsp:param name="..." value="..." />.

Be careful when using <jsp:forward> with unbuffered output. If the JSP file has any data in the out object, using this forward action will cause an IllegalStateException to be thrown when the page is displayed.

The response.sendRedirect() creates a new request object which doesn't carry any of old request information. The first request handler JSP page tells the browser to make a new request to the target servlet or JSP page. The URL shown in the browser therefore changes to the URL of the new page to which you redirect.

A redirect is slower than a forward because the browser has to make a new request. Another difference is that request scope objects are no longer available after a redirect because it results in a new request. If you need to pass data to the page you redirect to, you have to use a query string and pass them as request parameters or save the data in the session or application scope objects

Forward is faster than redirect but one disadvantage is that URL is not changed and also it works within the same web application. Also, when you choose to use forward, you need to think and confirm what must happen if the user reloads the page.

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the difference between jsp forward and response sendRedirect?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What is the difference between a forward and an introduction?

A forward is written by someone other than the author, providing context or commentary on the book. An introduction is typically written by the author, offering background information or insights into the content of the book.


What is the difference between forward and backwards scheduling?

jhfgg


What is the difference between forward kinemaics and reverse kinematics in robotics?

what is difference between forwad &amp; reverse kinamatic


What is the difference between forward difference and backward difference?

Given an infinitely convergent sequence pn with limit p, the forward difference is the measure of the difference between the current term and he next. The backward difference is the measure of the difference between the current term and the previous.i.e.forward difference: &Icirc;&rdquo;pn=pn+1 - pnbackward difference: &acirc;&circ;&Dagger;pn=pn - pn-1Also, note that since they are both expressed by pn, the forward difference is recognised by the use of a delta before the pn, and the backward difference by the use of a nabla.


What is the difference between 'I look forward to meeting you soon' and 'I look forward to meet you soon'?

The first is correct grammar.


What is the difference between a 3 speed and a 4 speed automatic car?

difference between 3 and four speed is, a 3 speed has 3 forward gears. a 4 speed has 4 forward gears


What is the difference between fourth and forth?

Fourth is like the number 4. Forth is to go forward.


What are the difference between forward engineering and reverse eng in uml?

forward engineering: the creation of code from models. reverse engineering: the creation of models from code.


What is the difference between forward lookup zone and reverse lookup zone in DNS?

Forward lookup is name-to-IP address; the reverse lookup is IP address-to-name.


What is the difference between forward slash and backward slash in c?

forward slash - division operator backward slash - special character (e.g. \n - newline) in C strings


What is the difference between power semiconductors and semiconductors?

power semiconductorspower semiconductors can drive large currents during forward biassemiconductorsemiconductors drive small currents during forward bias


What are voluntary and involuntary responses?

An involuntary response is when the doctor taps your knee with a hammer and your leg jerks forward. A voluntary response is when you are angry at your doctor and kick him hard by swinging your leg forward.