HI,
According to Sun specifications for servlets,
"The forward method of the RequestDispatcher interface may be called by the
calling servlet only when no output has been committed to the client. If output data
exists in the response buffer that has not been committed, the content must be
cleared before the target servlets service method is called. If the response has been
committed, an IllegalStateException must be thrown."
--------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class requestWriter extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException,ServletException
{
PrintWriter out = response.getWriter();
out.println("I am the source servlet ");
response.flushBuffer();
RequestDispatcher rd = request.getRequestDispatcher("requestWriter1");
rd.forward(request,response);
out.println("<BR> is committed <BR>"+response.isCommitted());
}
}
--------------------------------------------------
This servlet was deployed to Tomcat 4.1.6 . The output was
"I am the source servlet"
According to Sun specifications it should have thrown the IllegalStateException
bcaz i called RequestDispatcher.forward method after committing the response.
Need your comments.
-
RequestDispatcher and flushBuffer (1 messages)
- Posted by: King 26
- Posted on: November 03 2002 04:04 EST
Threaded Messages (1)
- RequestDispatcher and flushBuffer by Mani Venkatesan on November 09 2002 20:05 EST
-
RequestDispatcher and flushBuffer[ Go to top ]
- Posted by: Mani Venkatesan
- Posted on: November 09 2002 20:05 EST
- in response to King 26
How do you know that the servlet has not thrown the exception?
try this...
--------------------------------------------------
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
public class requestWriter extends HttpServlet{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException,ServletException
{
PrintWriter out = response.getWriter();
out.println("I am the source servlet ");
response.flushBuffer();
try { // -- added
RequestDispatcher rd = request.getRequestDispatcher("requestWriter1");
rd.forward(request,response);
out.println("<BR> is committed <BR>"+response.isCommitted());
} catch(Exception ex){ // -- added
System.out.println("exception thrown") ; // -- added
ex.printStackTrace() ; // -- added
} // -- added
}
}
--------------------------------------------------