日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

嵌入式Tomcat容器的参数(maxParameterCount)设定

發(fā)布時間:2025/3/21 编程问答 45 豆豆
生活随笔 收集整理的這篇文章主要介紹了 嵌入式Tomcat容器的参数(maxParameterCount)设定 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

背景

昨天同事遇到了error一起看了一下感覺比較重要在這記錄一下

基本情況是頁面上選中9K+的數(shù)據(jù)向后臺發(fā)送請求,然后系統(tǒng)就崩了。。。

?

error信息如下

More than the maximum number of request parameters (GET plus POST) for a single request ([10,000]) were detected.

Any parameters beyond this limit have been ignored. To change this limit, set the maxParameterCount attribute on the Connector.

簡說 單次請求的參數(shù)超出限制,通過maxParameterCount來更改容器的限制。

?

經(jīng)驗里對于tomcat容器的設(shè)定最對就是端口號,超時,最大線程的設(shè)置比較多

這個【maxParameterCount 】的設(shè)定還沒有過然后到網(wǎng)上去翻了

在官網(wǎng)的文檔(tomcat doc)里找到了如下

maxParameterCountThe maximum number of parameter and value pairs (GET plus POST) which will be automatically parsed by the container. Parameter and value pairs beyond this limit will be ignored. A value of less than 0 means no limit. If not specified, a default of 10000 is used. Note that FailedRequestFilter filter can be used to reject requests that hit the limit.
maxPostSizeThe 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.

簡說

maxParameterCount 是tomcat容器來限定你 單次請求的參數(shù)的最大數(shù)量,默認(rèn)是10000。所以通過這個屬性你可以根據(jù)情況給設(shè)定適當(dāng)?shù)闹怠.?dāng)然也有超出1w的情況怎么辦?

上面文檔里也有給出答案 小于0的設(shè)定可以禁用此制限。這也是很多網(wǎng)上資料設(shè)置-1的原因。

maxPostSize 是http-post單次請求內(nèi)容或者說數(shù)據(jù)的最大限制,默認(rèn)值為2M。同樣小于0的設(shè)定可以禁用此制限

?

具體使用

tomcat/conf/server.xml文件中找到如下節(jié)點

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" />

(這里有好幾個connector看自己用的是哪個端口的)

修改后

<Connector port="8080" protocol="HTTP/1.1" connectionTimeout="20000" redirectPort="8443" maxPostSize="-1" maxParameterCount="-1"/>

這是通常的做法,但有時如果tomcat容器內(nèi)置的話你可能都找不到server.xml文件,

比如spring boo項目內(nèi)置tomcat

這時候通常會想到 可以配置在application.properties里

然后翻一下看看application.properties里怎么配置

從spring-boot的doc看到只看到如下

server.tomcat.max-http-post-size=0 # Maximum size in bytes of the HTTP post content.

?

?

并沒有找到關(guān)于maxParameterCount信息,猜測不支持在配置文件里配置

繼續(xù)翻

找到可以寫在java類里的方法

@Beanpublic EmbeddedServletContainerFactory mbeddedServletContainerFactory() {TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory = new TomcatEmbeddedServletContainerFactory();tomcatEmbeddedServletContainerFactory.addConnectorCustomizers(connector ->{connector.setMaxPostSize(2);System.out.println("connector.getMaxPostSize: "+connector.getMaxPostSize());System.out.println("connector.getPort: "+connector.getPort());});return tomcatEmbeddedServletContainerFactory;}

?代碼本身并不多,過程比較曲折,大概說一下

EmbeddedServletContainerCustomizer

這是一個自定義內(nèi)置容器的接口,通過實現(xiàn)它可以創(chuàng)建內(nèi)置容器

然后還找到已經(jīng)實現(xiàn)了它類,

AbstractEmbeddedServletContainerFactory,
JettyEmbeddedServletContainerFactory,
TomcatEmbeddedServletContainerFactory,
UndertowEmbeddedServletContainerFactory

這里看到了定制tomcat容器的工廠類

繼續(xù)看看這個類里都什么可用(源碼有點多就不貼了貼一張截圖)

這里就是我們這次用到的函數(shù)了為什么標(biāo)記兩個因為上邊那個也可用,下面是官網(wǎng)給的說明

當(dāng)然其它的屬性也可以在這里設(shè)定貼一下官網(wǎng)連接就不再代碼體現(xiàn)了。

?

轉(zhuǎn)載于:https://www.cnblogs.com/zhufu9426/p/8275365.html

總結(jié)

以上是生活随笔為你收集整理的嵌入式Tomcat容器的参数(maxParameterCount)设定的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。