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 ?
To know recursion, you must first know recursion...
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):
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 ]
Joined: Jun 20, 2003
Gabriel was right, I spoke from my memory, got confused with request.sendRedirect().
Joined: Sep 03, 2003
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.
subject: Difference bwtween jsp:forward and RequestDispatcher forward.