[英]how to limit uploaded filesize in tomcat servlet
我需要為在tomcat上運行的servlet中的上傳文件設置max filesize。 我嘗試了在jetty上運行的multipart配置,但是tomcat只是忽略了它。 這意味着在tomcat服務器上部署甚至可以上傳大文件。 我的配置:
<servlet>
<servlet-name>myServlet</servlet-name>
<servlet-class>sk.test.MyServlet</servlet-class>
<multipart-config>
<max-file-size>1048576</max-file-size>
<max-request-size>104857600</max-request-size>
</multipart-config>
</servlet>
我已經嘗試過注釋配置,它也沒有用。
使用:Tomcat 7.0.54,Servlet 3.0
我將不勝感激,謝謝
設置最大文件大小的值,在servlet類或web.xml
配置之前使用注釋。 請參閱注釋中的maxFileSize
或xml config中的<max-file-size></max-file-size>
。
@MultipartConfig(
location="/tmp",
fileSizeThreshold=1024*1024, // 1 MB
maxFileSize=1024*1024*5, // 5 MB
maxRequestSize=1024*1024*5*5 // 25 MB
)
要么
<multipart-config>
<location>/tmp</location>
<max-file-size>20848820</max-file-size>
<max-request-size>418018841</max-request-size>
<file-size-threshold>1048576</file-size-threshold>
</multipart-config>
參考: https : //docs.oracle.com/javaee/7/tutorial/servlets011.htm
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.