Win a copy of Modern JavaScript for the Impatient this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Difference bwtween jsp:forward and RequestDispatcher forward.

 
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yo CattlePeople,

i came across this some-where:
For <jsp:forward> ,
"If the page output is buffered, the buffer is CLEARED prior to forwarding.

If the page output is buffered and the buffer was flushed, an attempt to forward the request will result in an IllegalStateException. "

I tested this by creating a JSP, and found it CORRECT.





Here, the buffer was set to null. then i wrote some template text and then the forward. hence, the forward throws an exception.

Then instead of <jsp:forward>, i the used RequestDispatcher to forward the request. But this time, it worked surprisingly. i thought, doing a requestDispatcher forward and <jsp:forward> are one at the same thing. Are they different ? if yes, then in what sense ?


Thanx,
Gaurav.
 
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dispatcher is transparent, which means the URL in browser doesn't change.
While if you use jsp:forward, you will be forwarded to another url, you will that in the browser.

Shiang
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

I think, that Shiang is wrong (sorry Shiang). If you use <jsp:forward .../>, the url does not change in the browser on the client side.

The different behaviour of RequestDispatcher's forward function and <jsp:forward page="..."/> is (from the jsp spec - chapter JSP5.5):


or



If you use Tomcat, you likely get:
The buffer size is 8192

If you try:


you do not get any exception in Tomcat, as the real buffer size is 8192, and the PageContext's forward method has no information, that you set the buffer size to 0.

remark:
According to the servlet spec, the container can set the buffer size bigger, than it's specified in the page directive or by the HttpServletResponse's setBufferSize() method.
[ November 19, 2004: Message edited by: Gabriel Forro ]
 
Shiang Wang
Ranch Hand
Posts: 96
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gabriel was right, I spoke from my memory, got confused with request.sendRedirect().
 
Gaurav Sahni
Ranch Hand
Posts: 56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanx for providing the insight, Gabriel.
Based on this, i would say

"The buffer size alloted by the container to a page (8192 KB, for eg. in case of Tomcat) is the buffer for JspWriter object, which will write to output finally.

However,if in the page, one tries to set the buffer using,
response.setBufferSize(0);
then, it does not changes this pre-allocated buffer of the JspWriter.

(then, what is actually changed ? )

Sorry for the confusion, again.
Gaurav.
 
I didn't say it. I'm just telling you what this tiny ad said.
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic