开发者

Why does Servlet.service() method return void and not an instance of ServletResponse?

Why does the service() method in the Servlet interface not return an instance of Servle开发者_开发知识库tResponse 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜