aspose file tools*
The moose likes Servlets and the fly likes problem in using MultipartRequest Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "problem in using MultipartRequest" Watch "problem in using MultipartRequest" New topic
Author

problem in using MultipartRequest

anuj khanna
Greenhorn

Joined: Jan 11, 2001
Posts: 20
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.
Detlev Beutner
Ranch Hand

Joined: Jul 13, 2001
Posts: 76
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: problem in using MultipartRequest