• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Multiple file uploading using oreilly MultipartRequest(urgent....)

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hello all
please let me know tht can i upload multiple files using MultipartRequest of oreilly... if yes then how can i poceed it....
plesase reply soon
regards
alok
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi! alok,

you can try out this code:it works perfectly well
Ist part:
import javax.servlet.http.*;
import com.oreilly.servlet.*;
import java.util.*;
public class T1 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,"give the real path e.g www/htdocs/document name",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>");
}
}
IInd part :
<html>
<head>
<title>File Upload</title>
</head>
<body bgcolor=bisque>
<form ACTION="http://server-ip address/servlet/T1" METHOD=post ENCTYPE="multipart/form-data" >
which file do you want to upload ? <input type=file name=file><br>
which file do you want to upload ? <input type=file name=file1><br>
which file do you want to upload ? <input type=file name=file2><br>
which file do you want to upload ? <input type=file name=file3><br>
which file do you want to upload ? <input type=file name=file4><br>
which file do you want to upload ? <input type=file name=file5><br>
<input type=submit value=submit>
</form>
</body>
</html>
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic