简体   繁体   English

java.io.IOException: 发布的内容类型不是 multipart/form-data

[英]java.io.IOException: Posted content type isn't multipart/form-data

I have written a jsp page for uploading image using POST method by using com.oreilly.servlet.multipart.MultipartParser actually file is successfully uploading and post values also getting correctly but it is throwing a exception我已经编写了一个jsp页面,用于使用com.oreilly.servlet.multipart.MultipartParser使用 POST 方法上传图像,实际上文件已成功上传,并且发布值也正确,但它引发了异常

java.io.IOException: Posted content type isn't multipart/form-data 
MultipartParser mp = null;
try{
 mp = new MultipartParser(request, 1*1024*1024); // 10MB
 }
 catch(Exception e){
 out.println("Exception1:"+e);
 }
while ((part = mp.readNextPart()) != null) {
        name = part.getName();
        if (part.isParam()) {
            ParamPart paramPart = (ParamPart) part;
            value = paramPart.getStringValue();
            if(name.equals("companyname") && value != null){                

            }

            if(name.equals("version") && value != null && name != null){

            }

        }
        else if (part.isFile()) {
            String getimagelogovalue="";
            FilePart filePart = (FilePart) part;
            String fileName = filePart.getFileName();
            if (fileName != null) {

            }
            else {}
            out.flush();
        }
    }   

You have:你有:

mp = new MultipartParser(request, 1*1024*1024); // 10MB

but by my calculations that is actually only 1Mb.但根据我的计算,实际上只有 1Mb。 Is the image you are trying to upload actually too large?您尝试上传的图像实际上是否太大? Try smaller images, fix your comment or fix your code.尝试较小的图像,修复您的评论或修复您的代码。

I think the code that you have written over here is the server side code, assuming that you are doing a post form JSP your code should look like following我认为您在此处编写的代码是服务器端代码,假设您正在执行发布表单 JSP,您的代码应如下所示

<FORM action="http://server.com/cgi/handle"
       enctype="multipart/form-data"
       method="post">
   <P>
   What is your name? <INPUT type="text" name="submit-name"><BR>
   What files are you sending? <INPUT type="file" name="files"><BR>
   <INPUT type="submit" value="Send"> <INPUT type="reset">
 </FORM>

See the enctype attribute.请参阅 enctype 属性。 Also can we see the client side(JSP) code?我们还能看到客户端(JSP)代码吗?

The code snippet is taken from http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2代码片段取自http://www.w3.org/TR/html401/interact/forms.html#h-17.13.4.2

I Just changed我刚改变

enctype="multipart/form-data"

to ENCTYPE="multipart/form-data"ENCTYPE="multipart/form-data"

in form tag在表单标签中

The Exception is resolved , and the form tag is below异常已解决,表单标签如下

 <form method="POST"  name="form1"  action="1StudentDVerify.jsp" ENCTYPE="multipart/form-data">


</form>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 发布的内容类型不是多部分/表单数据IO异常 - The Posted content type isn't multipart/form data IO exception java.io.IOException when posting multipart/form-data from Firefox 74 / 75 and using Apache AJP connector on server side - java.io.IOException when posting multipart/form-data from Firefox 74 / 75 and using Apache AJP connector on server side 原因:java.io.IOException: ObjectIdentifier() -- 数据不是 object ID(标签 = 48) - Caused by: java.io.IOException: ObjectIdentifier() -- data isn't an object ID (tag = 48) 如何处理java.io.IOException:表单数据损坏:com.oreilly.servlet.multipart.MultipartParser中提前结束? - How to handle java.io.IOException: Corrupt form data: premature ending occuring in com.oreilly.servlet.multipart.MultipartParser? 请求不包含多部分/表单数据或多部分/混合流,内容类型标头为false - the request doesn't contain a multipart/form-data or multipart/mixed stream, content type header is false 找不到适合请求类型 [java.util.LinkedHashMap] 和内容类型 [multipart/form-data] 的 HttpMessageConverter - no suitable HttpMessageConverter found for request type [java.util.LinkedHashMap] and content type [multipart/form-data] java.io.IOException:使用 SpringBoot 写入 Multipart 时出现异常 - java.io.IOException: Exception writing Multipart with SpringBoot Avro - java.io.IOException:不是数据文件 - Avro - java.io.IOException: Not a data file Java Spring:不支持内容类型“multipart/form-data;boundary;charset=UTF-8” - Java Spring: Content type 'multipart/form-data;boundary ;charset=UTF-8' not supported 使用 header Content-Type:multipart/form-data 发送 java POST 请求? - Send the java POST request with header Content-Type:multipart/form-data?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM