when is servlet response committed or flushed?
Asked Answered
M

2

4

According to javadoc:

in-request.getRequestDispatcher("/Test").forward(request,response);

forward should be called before the response has been committed to the client (before response body output has been flushed).Uncommitted output in the response buffer is automatically cleared before the forward.

I am getting confused when this response is committed or been flushed?

is this writing in println of printwriter.

Matsumoto answered 10/6, 2015 at 7:24 Comment(1)
This Javadoc, for which class and method did you take this reference from?Vineland
F
6

Calling flush() on the PrintWritercommits the response.

forward method allows one servlet to do preliminary processing of a request and another resource to generate the response.

You can have many out.write statements before forwarding but you can't call flush before forwarding. like

PrintWriter out = response.getWriter();
out.write("forwarding...\n");
rd.forward(request, response); //this is good

but if

out.write("forwarding...\n");
 out.flush();
 rd.forward(request, response); //this throws an exception
Fearless answered 10/6, 2015 at 7:40 Comment(0)
M
0

No it's not. Just when you flush it manually in your code like

response.flush().

Normally the servlet container do it for you after "your" method.

Mirage answered 10/6, 2015 at 7:34 Comment(1)
as u said Normally the servlet container do it for you after "your" method. then every time u called forward within a method this is guaranteed uncommitted.Matsumoto

© 2022 - 2024 — McMap. All rights reserved.