web.xml中的@MultipartConfig覆盖

编程入门 行业动态 更新时间:2024-10-09 22:20:47
本文介绍了web.xml中的@MultipartConfig覆盖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

所以我有这个servlet:

So I have this servlet :

@WebServlet(name = "StudentRegistrationUsn", urlPatterns = {"/university/student/registration"}) @MultipartConfig(maxFileSize = 10*1024*1024,maxRequestSize = 20*1024*1024,fileSizeThreshold = 5*1024*1024) public class ActionRegistrationServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //handle file upload }

一切正常,文件正在上传. 然后,我尝试覆盖web.xml中的fileSize和Threshold:

Everything works fine, files are uploading. Then I try to override the fileSize and Threshold in web.xml:

<servlet> <servlet-name>StudentRegistrationUsn</servlet-name> <multipart-config> <max-file-size>10485760</max-file-size> <max-request-size>20971520</max-request-size> <file-size-threshold>5242880</file-size-threshold> </multipart-config> </servlet>

这样做时,tomcat崩溃,并且每当我尝试访问该servlet时,它都会出现以下异常:

When I do that, tomcat crashes and whenever I try to access that servlet it gives the following exception:

The server encountered an internal error that prevented it from fulfilling this request. exception java.lang.NullPointerException sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) java.lang.ClassLoader.loadClass(ClassLoader.java:356) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1629) org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559) org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:461) org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99) org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929) org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407) org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002) org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585) org.apache.tomcat.util.AprEndpoint$SocketProcessor.run(AprEndpoint.java:1813) java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) java.lang.Thread.run(Thread.java:722)

推荐答案

web.xml中缺少<servlet-class>.基本上是由于要加载的类的名称为null导致此异常.

The <servlet-class> is missing in web.xml. This exception is basically caused because the name of the to-be-loaded class is null.

实际上,您需要重新定义所有内容,包括URL模式.

In fact, you need to redefine everything, including the URL patterns.

<servlet> <servlet-name>StudentRegistrationUsn</servlet-name> <servlet-class>com.example.StudentRegistrationUsn</servlet-class> <multipart-config> <max-file-size>10485760</max-file-size> <max-request-size>20971520</max-request-size> <file-size-threshold>5242880</file-size-threshold> </multipart-config> </servlet> <servlet-mapping> <servlet-name>StudentRegistrationUsn</servlet-name> <url-pattern>/university/student/registration</url-pattern> </servlet-mapping>

更多推荐

web.xml中的@MultipartConfig覆盖

本文发布于:2023-11-28 18:54:44,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1643570.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:web   xml   MultipartConfig

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!