Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用servlet上传文件_Java_Servlets_Upload_Jetty - Fatal编程技术网

Java 使用servlet上传文件

Java 使用servlet上传文件,java,servlets,upload,jetty,Java,Servlets,Upload,Jetty,大家好,我有个问题。我正在尝试使用servlet上载文件。我使用嵌入式jetty服务器 这是我的servlet代码: @MultipartConfig public class Upload extends HttpServlet { @Override protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

大家好,我有个问题。我正在尝试使用servlet上载文件。我使用嵌入式jetty服务器

这是我的servlet代码:

@MultipartConfig 
public class Upload extends HttpServlet {

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    File tempDir = new File(System.getProperty("java.io.tmpdir"));
    File writeDir = new File(tempDir.toString(), "test");

    request.getPart("file").write(writeDir.toString() + "/test.dat");

}
}

但当我尝试上载文件时,会出现以下错误:

java.lang.IllegalStateException: No multipart config for servlet

这些链接可能会帮助你和@ANyarThar我已经检查了这两个链接,但都没有解决我的问题。