在servlet中管理保持活动的http连接 [英] managing keep-alive http connection inside servlet

查看:74
本文介绍了在servlet中管理保持活动的http连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设浏览器发出请求
要求服务器使连接保持活动状态
(连接:保持活动状态).

Suppose a browser makes a request
asking for the server to keep the connection alive
(connection: keep-alive).

此请求需要调用servlet.

And this request requires the invocation of a servlet.

在我的Servlet内部,我应该选择最好的 发送数据的方式(分块或表示
身体的长度)??

Inside my servlet should I care to choose the best way to send data (chunked or indicating
the lenght of the body ) ??

如果服务器为我这样做,为什么在我的servlet中,
我可以修改标题,例如:
内容长度
并传输编码?

if the server does that for me , why , inside my servlet ,
I'm able to modyfy headers like:
content-length
and transfer encoding ?

谢谢

推荐答案

如果您预先知道主体长度,则应在编写主体之前设置Content-Length标头.

If you know the body length up front, you should set Content-Length header before writing body.

否则什么都不做; servlet容器应该能够自动添加Transfer-Encoding,并对您的主体进行块化处理.这受客户端/请求版本和Connection标头的约束.

Otherwise do nothing; the servlet container should be able to automatically add Transfer-Encoding, and chunk-ify your body. That is subject to client/request version and Connection header.

这篇关于在servlet中管理保持活动的http连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆