Hi everyone,
I wanna upload a file to Javawebserver.I've downloaded
"com.oreille.servlet.*" package from
www.servlets.com and has set the classpath.Everything is compiling fine and i wrote the following code in Html page
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form ACTION="http://localhost:8080/servlet/Test.class" METHOD=post ENCTYPE="multipart/form-data" >
what is your name ? <input type = text name=submitter> <br>
which file do you want to upload ? <input type=file name=file><br>
<input type=submit value=submit>
</form>
</body>
</html>
But,when i click on the submit button i get an error as "Http404" not found.
I wrote the following code as my
servlet public class
Test 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,"./public_html/temp",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>");
}
}
pl revert back as this is urgent
Thanks
sridhar