如何限制tomcat 8中的帖子大小?如何对其进行自定义回复? [英] how to limit post size in tomcat 8? How to make a custom reply for it?

查看:57
本文介绍了如何限制tomcat 8中的帖子大小?如何对其进行自定义回复?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在server.xml文件中配置了此

I have this configured in my server.xml file

<Connector URIEncoding="UTF-8" connectionTimeout="20000" maxHttpHeaderSize="65536" **maxPostSize="1024"** port="8080" protocol="HTTP/1.1" redirectPort="8443"/>

但是,请求的传递超过1 KB,就好像从未设置maxPostSize一样.谁能建议会导致这种情况的原因?

However, requests more than 1 KB pass as if maxPostSize is never set. Can anyone suggest what can cause that?

另一件事,如果帖子大小超过1 KB,我想知道如何从tomcat发出自定义的http答复

Another thing, I would like to know how to make a custom http reply from tomcat if the post size is more than 1 KB

UPDATE 自从我在这个问题上待了很长时间以来.我有机会对tomcat的源代码进行了检查,以准确检查此处发生的情况:单击此处

我注意到从第2541行到2550年,尽管文档说"maxPostSize:最大大小(以字节为单位)",但它们使用的是getContentLength().为什么会以字节为单位?对我来说,字符看起来更多,可以在servlet端完成.有人可以解释我在这里缺少什么吗?

I noticed from lines 2541 till 2550, they are using getContentLength() although the documentation says "maxPostSize: The maximum size in bytes". How come could this be in bytes? It looks more to characters count to me and it can be done in servlet side. Can someone explain what I am missing here?

推荐答案

根据

According to tomcat doc the maxPostSize is 2M.

容器FORM URL参数解析将处理的POST的最大大小(以字节为单位).可以通过将此属性设置为小于零的值来禁用该限制.如果未指定,则此属性设置为2097152(2兆字节).请注意,可以使用FailedRequestFilter拒绝超过此限制的请求.

The maximum size in bytes of the POST which will be handled by the container FORM URL parameter parsing. The limit can be disabled by setting this attribute to a value less than zero. If not specified, this attribute is set to 2097152 (2 megabytes). Note that the FailedRequestFilter can be used to reject requests that exceed this limit.

如果要更改默认值,请在下面的文件位置中更改:

If you would to change the default values then change in the file location below:

$ CATALINA_HOME/conf/server.xml

$CATALINA_HOME/conf/server.xml

示例:

<Connector port="80" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443"
                maxPostSize="6291456" />

以字节为单位的大小6291456 *(1024 * 1024)= 6M

The size in bytes 6291456*(1024*1024)=6M

注意:请确保在进行更改后重新启动服务器.

Note: Please make sure you restart the server after making the changes.

这篇关于如何限制tomcat 8中的帖子大小?如何对其进行自定义回复?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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