Tomcat maxpostsize 值被 XMLHttpRequest 忽略?
我正在使用 Spring 3 和 jquery 开发一个 Web 应用程序,并且使用 ajax 上传脚本将文件发送到服务器(Tomcat 7.0.22)。内容类型为 application/octet-stream
的文件已发布到服务器 服务器将其解析为字节数组。然而,尽管我什至在 tomcat 配置中显式地将 maxpostsize
的值设置为 2097152,但此设置似乎根本没有效果。例如,我能够(本地)上传足够大(> 1 GB)的文件以使服务器崩溃(内存不足)。以下是来自 firebug 的请求标头:
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
X-File-Name some-pdf.pdf
Content-Type application/octet-stream
Referer http://localhost:8080/myapp/
Content-Length 9369597
Cookie JSESSIONID=F237BA8176D158A297BAFA7F57A98A5F;
Pragma no-cache
Cache-Control no-cache
这是 Tomcat 的连接器配置
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxPostSize="2097152"/>
I am developing a web application with Spring 3 and jquery and i am using an ajax upload script to send files to the server (Tomcat 7.0.22). A file is posted to the server with a content-type of application/octet-stream
and the server parses it fine as a byte array. However although i have even explicitly set in the tomcat configuration the value of maxpostsize
to 2097152, this setting appears to have no effect at all. For example i am able to upload files (locally) large enough (> 1 GB) to crash the server (out of memory). Here are the request headers from firebug:
Host localhost:8080
User-Agent Mozilla/5.0 (Windows NT 6.1; WOW64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
X-Requested-With XMLHttpRequest
X-File-Name some-pdf.pdf
Content-Type application/octet-stream
Referer http://localhost:8080/myapp/
Content-Length 9369597
Cookie JSESSIONID=F237BA8176D158A297BAFA7F57A98A5F;
Pragma no-cache
Cache-Control no-cache
Here is the Tomcat's connector config
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443"
maxPostSize="2097152"/>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
虽然这是一个老问题:
正如 Request.java,仅针对“application/x-www-form-urlencoded”内容类型考虑 maxPostSize,并且不受请求方式的影响(“正常”与 xhr)。
Although this is an old question:
As can be seen in Request.java, maxPostSize is taken into account only for the "application/x-www-form-urlencoded" content type and is not affected by how the request is made ("normal" vs. xhr).