web.xml中的@MultipartConfig覆盖 [英] @MultipartConfig override in web.xml

查看:567
本文介绍了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.net.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覆盖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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