• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

which one is fast

 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all

forword() and sendRedirect
which one is fast
pl. let me know

thanks
shrawan
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrawan Bhageria:
forword() and sendRedirect
which one is fast


Both are different and use for different purposes. Performance should not be the issue here. If you are curious, then forword() should be faster. Its just a thought nothing sure about it.

If you are thinking that both are the same and performance is the only difference then please refer to the doc.

Thanks.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The forward() is faster than sendredirect(). The sendRedirect() involves a round trip.
 
Adeel Ansari
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Pradip Bhat:
The forward() is faster than sendredirect(). The sendRedirect() involves a round trip.


Yes. Because of the same reason I thought forword() should be faster. Thanks for giving me the surity.
 
vikassheel gupta
Ranch Hand
Posts: 53
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
ya pradip is very right
that forward is faster than sendRedirect bcz of round trip
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I hope you're not making your decision bases on speed alone.
I would try to understand how each method works and determine which best suites my needs.

There are advantages and disadvantages to both.
The difference in speed is almost trivial compared with the other differences.

Build your app for clarity, profile it to find out where the bottlenecks are and THEN decide where to optimize.
 
vu lee
Ranch Hand
Posts: 206
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forward is not restricted to security resource but redirect is.
 
Shrawan Bhageria
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all
what does it mean
The sendRedirect() involves a round trip.
thanks
regards
shrawan
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by vu lee:
Forward is not restricted to security resource but redirect is.


Sorry, I did not understand.
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sendRedirect involves a browser to pull a new target, so if people from mars browse your site,
 
srinivas rao
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
forward() method is faster than sendRedirect
But the main thing is forward() works only within the webapplication.
But whereas with the sendRedirect() method we can redirect to any webapplication.(which cant be done using forward() method.)

But if u want to redirect a servlet using forward() method only which is in other webapplication u can also do that. For this you need to get an object of ServletContext and then use forward() method.

see the code below:-
ServletContext servletcontex=ServletContext.getContext();
RequestDispatcher requestDispatcher=ServletContext.getRequestDispatcher("/contextname");
requestDispatcher.forward(request,response);
Note:- Before doing this u change your CrossContext attribute to true in your context in server.xml file since it is false by default
 
Jack Wiesenthaler
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Shrawan Bhageria:
hi all
what does it mean
The sendRedirect() involves a round trip.
thanks
regards
shrawan


By "round trip" he means it goes from the server to the client (browser) and then another request is originated from the browser.
When you use sendRedirect it sends a HTTP code 302 to the browser with the new URL. The browser will then initiate a HTTP GET on the new URL.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic