[英]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.