• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

problem in using MultipartRequest  RSS feed

 
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i'm trying to use MultipartRequest but i'm getting exception
java.io.IOException: Posted content type isn't multipart/form-data
at com.oreilly.servlet.multipart.MultipartParser.(MultipartParser.java:119)
at com.oreilly.servlet.multipart.MultipartParser.(MultipartParser.java:83)
at com.oreilly.servlet.MultipartRequest.(Compiled Code)
at pt.doPost(Compiled Code)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:747)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
at sun.servlet.http.HttpServerHandler.sendResponse(HttpServerHandler.java:165)
at sun.servlet.http.HttpServerHandler.handleConnection(Compiled Code)
at sun.servlet.http.HttpServerHandler.run(Compiled Code)
at java.lang.Thread.run(Thread.java:479)
i'm using servletrunner inJSDK and i've put the com.jar file in jdk1.2.1\jre\lib\ext folder
what shall i do how shall i run the program the code of the program is
import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.MultipartRequest;

public class pt extends HttpServlet{
public void doPost(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException{
res.setContentType("text/html");
PrintWriter out=res.getWriter();
try{

MultipartRequest multi=new MultipartRequest(req,"f:/avoidmiddleman",1024*1024);
out.println("<HTML>");
out.println("<HEAD><TITLE>Upload File</TITLE></HEAD>");
out.println("<BODY>");
out.println("<H1>UploadTest</H1>");
out.println("<H3>Params:</H3>");
out.println("<PRE>");
Enumeration params=multi.getParameterNames();

while(params.hasMoreElements()){

String name=(String)params.nextElement();
System.out.println(multi.getContentType(name));
String value=multi.getParameter(name);
out.println(name+"="+value);
}
out.println("</PRE>");
//show which file we received
out.println("<H3>Files:</H3>");
out.println("<PRE>");
Enumeration files =multi.getFileNames();
while(files.hasMoreElements())
{
String name=(String)files.nextElement();
String filename=multi.getFilesystemName(name);
String type=multi.getContentType(name);
File f=multi.getFile(name);
out.println("name:"+name);
out.println("filename:"+filename);
out.println("type:"+type);
if(f != null){
out.println("length:"+f.length());
out.println();
}
out.println("</PRE>");
}
}
catch(Exception ex)
{
out.println("<PRE>");
ex.printStackTrace(out);
out.println("anuj khanna");
out.println("</PRE>");
}
out.println("</BODY></HTML>");
}
}


please help fast.very very urgent.thankyou.
 
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's likely that the HTML-Page sending the POST does not encode the Upload as "multipart/form-data" (must be something like: <FORM METHOD="post" ACTION="pt" NAME="[name]" ENCTYPE="multipart/form-data">. So look at that code, maybe you'll see it yourself; if not, please repost that HTML-code, and we will see...
Hope it helps
Detlev
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!