If I understand your question: the reason the DispatchResponse is 
committed is that you have called .flush() explicitly on the original 
HttpServletRequest (HttpResponse).

This is nothing strange. Why could you want to create a wrapper to 
"hide" the commited state, so that you can perform forward???
forward means "instead of"
include means "also"

You cannot first generate or include content, flush it to the client 
(sent over the network to the web browser) and then say "Oh wait, I 
changed my mind, I want to send this content instead" (=forward).
If your design requires that the response is not commited, there is 
something wrong with your desing.
You will need to decide what to send before you start writing to the 
response stream/writer.

An alternative approach, if for some reason you must do it this way, is 
to create wrapper classes that put the included content in a buffer 
(think ByteArrayOutputStream) until you are sure you want to send it to 
the client, then you write the buffer to the actual response.


 /Mattias


Ilya Kasnacheev wrote (2008-03-07 11:14):
> Let's say we've got a servlet such as
> ==
>  protected void doGet(HttpServletRequest request, HttpServletResponse 
> response)
>    throws ServletException, IOException
>  {
>   RequestDispatcher rd = getServletContext().getRequestDispatcher("/target");
>   
>   String s;
>   s = "Launcher: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   System.err.println(s);
>   
>   response.setContentType("text/plain; charset=koi8-r");
>   PrintWriter out = response.getWriter();
>   s = "Launcher: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   out.println(s);
>   System.err.println(s);
>   
>   rd.include(request, response);
>   
>   out.flush();
>   s = "Launcher: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   out.println(s);
>   System.err.println(s);
>   
>   rd.include(request, response);
>   s = "Launcher: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   out.println(s);
>   System.err.println(s); 
>   
>   out.flush();
>  }
> ==
>
> Let's say we have another servlet such as
> ==
>  protected void doGet(HttpServletRequest request, HttpServletResponse 
> response)
>    throws ServletException, IOException
>  {
>   String s;
>   s = "Target: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   System.err.println(s);
>   
>   response.setContentType("text/plain; charset=koi8-r");
>   
>   PrintWriter out = response.getWriter();
>   s = "Target: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   System.err.println(s);
>   out.println(s);
>   
>   out.flush();
>   s = "Target: response is " 
>    + response.getClass().getName() 
>    + (response.isCommitted() ? ", commited" : "");
>   out.println(s);
>   System.err.println(s);
>  }
> ==
>
> Let's say we map them to '/launcher' and '/target'.
> Let's say we call target on resin, we will get this on stderr:
>
> ==
> Launcher: response is com.caucho.server.http.HttpResponse
> Launcher: response is com.caucho.server.http.HttpResponse
> Target: response is com.caucho.server.webapp.DispatchResponse
> Target: response is com.caucho.server.webapp.DispatchResponse
> Target: response is com.caucho.server.webapp.DispatchResponse, commited
> Launcher: response is com.caucho.server.http.HttpResponse, commited
> Target: response is com.caucho.server.webapp.DispatchResponse, commited
> Target: response is com.caucho.server.webapp.DispatchResponse, commited
> Target: response is com.caucho.server.webapp.DispatchResponse, commited
> Launcher: response is com.caucho.server.http.HttpResponse, commited
> ==
> You see? DispatchResponse isComitted() always on the second run. Before 
> Target 
> did anything with that response.
> I don't think that's correct because it guaranties that some servlets will 
> break. Like those who use forward().
>
> I'll investigate that case further.
> Is there anything in J2EE docs to cover up current behavior?
+
>         response = new HttpServletResponseWrapper(response) {
>          public boolean isCommitted()
>          {
>           return false;
>          }
>         };



_______________________________________________
resin-interest mailing list
resin-interest@caucho.com
http://maillist.caucho.com/mailman/listinfo/resin-interest

Reply via email to