Showing posts with label web application. Show all posts

Following are the steps you might try... download common-fileupload at http://commons.apache.org/fileupload. create web application proje...

Following are the steps you might try...
  1. download common-fileupload at http://commons.apache.org/fileupload.
  2. create web application project on netbeans
  3. add library common-fileupload and all dependencies (common-logging, common-beanutils)
  4. Create html form with file upload input in it, don't forget to set form enctype to multipart/form-data
  5. Create a servlet
  6. Create folder "destination" in the root web
  7. Create following script to handle upload file


1:    boolean isMultipart = ServletFileUpload.isMultipartContent(request);  
2:    if (isMultipart) {  
3:      try {  
4:        FileItemFactory factory = new DiskFileItemFactory();  
5:        ServletFileUpload upload = new ServletFileUpload(factory);  
6:        List items = upload.parseRequest(request);  
7:        Iterator iter = items.iterator();  
8:        String myfile = "";  
9:        while (iter.hasNext()) {  
10:          FileItem item = (FileItem) iter.next();  
11:          if (!item.isFormField()) {  
12:            myfile = item.getName();  
13:            File fullFile = new File(contract);  
14:            File savedFile = new File(getServletContext().getRealPath("/destination"),  
15:    fullFile.getName());  
16:            try {  
17:              item.write(savedFile);  
18:            } catch (Exception ex) {  
19:              Logger.getLogger(ControllerServlet.class.getName()).log(Level.SEVERE, null, ex);  
20:            }  
21:      }  
22:    }  

uploaded file should be available on "destination" folder :)

90% Wizard :)


90% Wizard :)

Affablebean, web ecommerce tutorial on Java Enterprise platform Ingredients : JSP JSTL JPA EJB Run on Glashfish 3

Affablebean, web ecommerce tutorial on Java Enterprise platform

Ingredients :

  • JSP
  • JSTL
  • JPA
  • EJB
Run on Glashfish 3