Why does the service()
method in the Servlet interface not return an instance of ServletResponse but rather work on the ServletResponse object provided by the container?
In simple words why is the service method of the Servlet interface like:
public void service(ServletRequest request, ServletResponse response);
and NOT like:
public ServletResponse service(ServletRequest request);
If the response object is provided by the servlet container, it can control how things like buffering are handled. For example, suppose you created your own ServletResponse
- how would the container manage the ability to stream the response if it's over a certain length, instead of buffering the data?
It uses a Response the container builds partially for it. It doesn't build the response out of whole cloth. It'd have to be an argument in any event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With