[Logo]
Forums Register Login
problem in using MultipartRequest
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.
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

This thread has been viewed 2254 times.

All times above are in ranch (not your local) time.
The current ranch time is
Oct 22, 2018 23:04:59.