Originally posted by Manohar Karamballi:
Hai Sai!
May be it has to do with something in registering ur servlet in ur server
Rgds
Manohar
Originally posted by arvind:
hi! sridhar,
u can try out this code ,it works:
Ist part:
<html>
<head>
<title>File Upload</title>
</head>
<body bgcolor=bisque>
<form ACTION="http://localhost:8080/servlet/upload" METHOD=post ENCTYPE="multipart/form-data" >
which file do you want to upload ? <input type=file name=file><br>
<input type=submit value=submit>
</form>
</body>
</html>
IInd part:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class upload 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,"../image/trim",5*1024*1024);
out.println("<html>");
out.println("<head><title>UploadTest</head></title>");
out.println("<body>");
out.println("<h1>upLoadTest</h1>");
out.println("<pre>");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()){
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println( name + " = " + value);
}
out.println("</pre>");
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("file name : "+ filename);
out.println("type : "+type);
if (f!=null){
out.println("length : " +f.length());
out.println();
}
out.println("</pre>");
}
}
catch(Exception e){
out.println("<pre>");
System.out.println(e);
e.printStackTrace(out);
out.println("</pre>");
}
out.println("</body> </html>");
}
}