gudii9
asked on
response.sendRedirect, RequestDispatcher.forward
Hi,
Session Data Sharing using response.sendRedirect, RequestDispatcher.forward
prefer response.sendRedirect instead of RequestDispatcher.forward
since
User sees JSP URL (user only able to see servlet URL in case RequestDispatcher.forward)
There is need of Two round trips to client (whereas only one with forward)
I wonder why two round trips in case of response.sendRedirect???? whereas only one for RequestDispatcher.forward
sendRedirect has advantaes of User can separately visit JSP page, bookmark JSP page
sendRedirect has Disadvantage user can visit directly JSP page without going through servlet first so JSP data may not be there, so need to code JSP page to detect this situation
How to code JSP page to detect this situation???
I wonder what these advantages, disadvantages means in detail, practically???
response.sendRedirect, RequestDispatcher.forward concept is there in servlets as well apart from JSP.
I remember reading only RequestDispatcher.forward in servlets not response.sendRedirect
Please advise.
Any links resources ideas highly appreciated. Thanks in advance
Session Data Sharing using response.sendRedirect, RequestDispatcher.forward
prefer response.sendRedirect instead of RequestDispatcher.forward
since
User sees JSP URL (user only able to see servlet URL in case RequestDispatcher.forward)
There is need of Two round trips to client (whereas only one with forward)
I wonder why two round trips in case of response.sendRedirect???? whereas only one for RequestDispatcher.forward
sendRedirect has advantaes of User can separately visit JSP page, bookmark JSP page
sendRedirect has Disadvantage user can visit directly JSP page without going through servlet first so JSP data may not be there, so need to code JSP page to detect this situation
How to code JSP page to detect this situation???
I wonder what these advantages, disadvantages means in detail, practically???
response.sendRedirect, RequestDispatcher.forward concept is there in servlets as well apart from JSP.
I remember reading only RequestDispatcher.forward in servlets not response.sendRedirect
Please advise.
Any links resources ideas highly appreciated. Thanks in advance
ASKER
is
response.setStatus()
response.setHeader()
does same thing as explained in this video??
http://www.youtube.com/watch?v=CeMqHGXQuPc
Please advise
response.setStatus()
response.setHeader()
does same thing as explained in this video??
http://www.youtube.com/watch?v=CeMqHGXQuPc
Please advise
ASKER
>>>In general, a forward should be used if the operation can be safely repeated upon a browser reload of the resulting web page; otherwise, redirect must be used. Typically, if the operation performs an edit on the datastore, then a redirect, not a forward, is required. This is simply to avoid the possibility of inadvertently duplicating an edit to the database.
More explicitly (in terms of common SQL operations) :
for SELECT operations, use a forward
for INSERT, UPDATE, or DELETE operations, use a redirect
I have not understood above explanation. can you please elaborate
The author makes a comparison between SQL statement and HTTP actions. He probably means that with SELECT you cannot change the data, so a forward can be used. Otherwise use a redirect.
ASKER
There is similar discussion here
http://javapapers.com/jsp/difference-between-forward-and-sendredirect/
where author explained the concept in opposite way..like use forward if you want to do paymentProcessing also along with displayingInfo(where as redirect only for displayingInfo so that if user refreshes paymentProcessing wil not happen)
http://javapapers.com/jsp/difference-between-forward-and-sendredirect/
For example, database update and data display can be separated by redirect. Do the PaymentProcess and then redirect to displayPaymentInfo. If the client refreshes the browser only the displayPaymentInfo will be done again and PyamenProcess will not be repeated. But if you use forward in this scenario, both PaymentProcess and displayPaymentInfo will be re-executed sequentially, which may result in incosistent data.
where author explained the concept in opposite way..like use forward if you want to do paymentProcessing also along with displayingInfo(where as redirect only for displayingInfo so that if user refreshes paymentProcessing wil not happen)
ASKER
Please advise
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I am not sure I understand this. You are the one who's doing the redirect/forward, why would you want to detect your own actions?
When to use redirect and forward.