aspose file tools*
The moose likes Servlets and the fly likes which one is fast Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "which one is fast" Watch "which one is fast" New topic
Author

which one is fast

Shrawan Bhageria
Ranch Hand

Joined: Jun 20, 2005
Posts: 52
hi all

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

thanks
shrawan
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Feb 27, 2002
Posts: 8919

The forward() is faster than sendredirect(). The sendRedirect() involves a round trip.


Groovy
Adeel Ansari
Ranch Hand

Joined: Aug 15, 2004
Posts: 2874
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

Joined: Aug 02, 2005
Posts: 53
hi
ya pradip is very right
that forward is faster than sendRedirect bcz of round trip


Warm Regards<br />vikassheelgupta<br />9911005168
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
vu lee
Ranch Hand

Joined: Apr 19, 2005
Posts: 189
Forward is not restricted to security resource but redirect is.
Shrawan Bhageria
Ranch Hand

Joined: Jun 20, 2005
Posts: 52
hi all
what does it mean
The sendRedirect() involves a round trip.
thanks
regards
shrawan
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8919

Originally posted by vu lee:
Forward is not restricted to security resource but redirect is.


Sorry, I did not understand.
D Rog
Ranch Hand

Joined: Feb 07, 2004
Posts: 472

sendRedirect involves a browser to pull a new target, so if people from mars browse your site,


Retire your iPod and start with HD Android music player Kamerton | Minimal J2EE container is here | Light weight full J2EE stack | and build tool | Co-author of "Windows programming in Turbo Pascal"
srinivas rao
Greenhorn

Joined: Feb 01, 2005
Posts: 10
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

Joined: Jul 26, 2001
Posts: 75
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: which one is fast