如何在 Java servlet 容器上指定 Http 请求超时参数

发布于 2024-08-05 02:58:36 字数 160 浏览 3 评论 0原文

我试图了解在哪里可以为到达我的 servlet(或我的所有 servlet)的所有请求配置请求超时?正如我所想,这是一个容器属性吗? 另外,这对不同的浏览器有何影响?它们都符合容器规定的参数吗? 或者也许请求超时时间甚至不是我可以控制的并且每个浏览器自己决定这个? (需要明确的是,我不是在谈论会话超时)

I'm trying to understand where I can configure a request timeout for all requests arriving to a servlet of mine (or all of my servlets)? Is that, as I think, a container property?
Also, how does this affect different browsers? Do they all comply to the parameter the container dictates?
Or maybe the request timeout time isn't even something I can control and each browser decides on this on its own?
(Just to be clear I'm not talking about session timeout)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

孤云独去闲 2024-08-12 02:58:36

客户端的超时(即等待 HTTP 请求响应的时间)由客户端确定。对于 IE,请参阅,对于 Firefox,请参阅这个

您无法从服务器控制此超时。

The timeout from a client (i.e. how long it waits for a response to an HTTP request) is determined at the client. For IE, see this, and for Firefox see this.

You can't control this timeout from the server.

不交电费瞎发啥光 2024-08-12 02:58:36

即使你无法控制客户端超时,你也可以让服务器非常不耐烦:) 例如,在 Tomcat 上,你可以在连接器中执行此操作,

<Connector port="8080"  
  ...
  connectionTimeout ="5000"
  disableUploadTimeout="false" />

这使得服务器只等待 5 秒并关闭连接。浏览器将收到连接关闭错误。您可以将其视为客户端超时。

当然,这只适用于超时是由服务器引起的,而不是浏览器和服务器之间的连接问题。

Even though you can't control client timeout, you can make server very impatient :) For example, on Tomcat, you can do this in your connector,

<Connector port="8080"  
  ...
  connectionTimeout ="5000"
  disableUploadTimeout="false" />

This makes server only wait 5 seconds and close the connection. Browser will get a connection closed error. You can treat it the same as timeout in client.

Of course, this only works if the timeout is caused by the server, not connectivity issues between browser and server.

云之铃。 2024-08-12 02:58:36

您无法从服务器控制客户端超时。但是,当长时间运行的操作繁忙时,您可以时不时地将数据发送回客户端。这将防止客户端超时,并可用于向用户显示进度等。将从响应中获取的数据写入到OutputStream或Writer中,并调用flush将部分数据发送到客户端。

You cannot control the client timeout from the server. However you may be able to send data back to the client every now and then while your long running operation is busy. This will prevent the client from timing out and can be used to display progress to the user etc. Write data to the OutputStream or Writer obtained from the response and call flush to send partial data to the client.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文