• Skip to main content
  • Skip to primary sidebar
  • Skip to secondary sidebar
  • Skip to footer

Computer Notes

Library
    • Computer Fundamental
    • Computer Memory
    • DBMS Tutorial
    • Operating System
    • Computer Networking
    • C Programming
    • C++ Programming
    • Java Programming
    • C# Programming
    • SQL Tutorial
    • Management Tutorial
    • Computer Graphics
    • Compiler Design
    • Style Sheet
    • JavaScript Tutorial
    • Html Tutorial
    • Wordpress Tutorial
    • Python Tutorial
    • PHP Tutorial
    • JSP Tutorial
    • AngularJS Tutorial
    • Data Structures
    • E Commerce Tutorial
    • Visual Basic
    • Structs2 Tutorial
    • Digital Electronics
    • Internet Terms
    • Servlet Tutorial
    • Software Engineering
    • Interviews Questions
    • Basic Terms
    • Troubleshooting
Menu

Header Right

Home » Servlet » Examples » What Is File Uploading? Important Classes Of Javazoom.Api
Next →
← Prev

What Is File Uploading? Important Classes Of Javazoom.Api

By Dinesh Thakur

The process of selecting file from the client machine file system and sending that file to the server machine system is known as file uploading. File uploading and downloading using servlet-api is a complex process, that is why industry uses JavaZoom 3rd party API.

download it from www.javazoom.net as zip file.

JavaZoom-API comes in the form of three jar file.

1. uploadbean.jar
2. cos.jar
3. struts.jar

IMPORTANT CLASSES OF JAVAZOOM.API

1. MultiPartFormDataRequest: Represents all the uploaded files from servlet/jsp program. To create this object we need HttpServletRequest object.

2. UploadBean: Allows to specify the file uploading related roperties and to complete file uploading operation.

3. UploadFile: Represents each file that has been uploaded. To select file from the client machine file system we can use the file uploading component.

<input type='file' name='fs'>

While performing file uploading the form page must generate “POST” methodology based request having the encryption type=“multipart/form-data”

Step 1: Prepare the deployment directory structure of web application.

Step 2: Develop the source code of above servlet program or web Application 

UplSrv.java

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javazoom.upload.*;
import java.util.*;
public class UplSrv extends HttpServlet {
 public void doPost (HttpServletRequest req, HttpServletResponse res) 
 throws ServletException, IOException {
 PrintWriter pw = res.getWriter ();
 try {
 //set location for saving uploaded files
 UploadBean upb = new UploadBean ();
 upb.setFolderstore ("c:/store");
 upb.setOverwrite (false);
 MultipartFormDataRequest nreq = new MultipartFormDataRequest(req);
 upb.store (nreq); //completes files uploding
 // display names of the uploaded files
 pw.println ("The uploaded files are");
 Hashtable ht = nreq.getFiles (); //gives all uploaded files
 Enumeration e = ht.elements ();
 while (e.hasMoreElements ()) {
   UploadFile file = (UploadFile) e.nextElement ();
   pw.println (file.getFileName () + " ");
 } //while
 } //try
 catch (Exception e) {
   pw.println (e);
 } //catch
 } //dopost ()
} //class

Explanation of the above program

In the above program our intention is uploading two files.

In the above program all the five packages are imported. Here javax.servlet

package is imported because the method doPost (-,-) throws exceptions such as ServletException and IOException for this reason we import javax.servlet package. As the class extends from HttpServlet, this HttpServlet class present in the javax.servlet.http package and HttpServletRequest and HttpServletResponse interfaces are also present within the javax.servlet.http package. That’s why it’s necessary to import the javax.servlet.http and also import javazoom.upload.*;

UploadBean, MultipartFormDataRequest classes are present in javazoom. uploadpackge, so it is necessary to import javazoom.upload package. Also, import java.util.* package because Hashtable class, Enumeration interface are present in java.utilPackage, and also import:

• Print Writer pw= res.getWriter ( );

Within the service method i.e. service (-,-), to print the output in the browser window PrintWriter class is used. PrintWriter class and the service (-,-) exception i.e IOException are present in java.io package. So, java.io.*; package is imported.

• res.setContentType (“text/html”);

set the content Type

• UploadBean upb = new UploadBean ();

Creates the object of Upload Bean class

• upb.setFolderstore (“c:/store”);

Sets location for saving uploaded files

• MultipartFormDataRequest nreq = new MultipartFormDataRequest (req);

Creates the object MultipartFormDataRequest

• upb.store (nreq);

This method completes the file uploading.

• Hashtable ht = nreq.getFiles ();

Gives all uploaded files in Hashtable

• Enumeration e = ht.elements ();

Collects all files from Hashtable

• UploadFile file = (UploadFile) e.nextElement ();

Reads files sequentially from Enumeration

• pw.println (file.getFileName ()+ “ ”);

Gets the uploaded file name

upload.html

<center>
 <form method=“post” action=“upload” name=“upload” enctype=“multipart/form-data”>
  File 1 : <input type= “file” name=“uploadfilel” value= ‘Browse’/> <br> <br>
  File 2 : <input type=“file” name= “uploadfile2” value= ‘Browse’/> <br> <br>
  <input type=“Submit” value= “Upload”>
</form>
</center>

Step 3: Compile the source files of all servlet programs.

Step 4: Configure all the four servlet programs in web.xml file having four different url patterns.

web.xml

<web-app>
 <servlet>
  <servlet-name> abc </servlet-name>
  <servlet-class> UplSrv </servlet-class>
 </servlet>
 <servlet-mapping>
  <servlet-name> abc </servlet-name>
  <url-pattern> /upload </url-pattern>
 </servlet-mapping>
 <welcome-file-list>
  <welcome-file> upload.html </welcome-file>
 </welcome-file-list>
</web-app>

Step 5: Start the server (Tomcat).

Step 6: Deploy the web application and Copy UploadApp folder to Tomcat_home\webapps folder.

Step 7: Test the web application.

Open browser window type this urls: https://ecomputernotes.com:2020/UploadApp/ upload.html

You’ll also like:

  1. What is JDBC API? Important Goals of JDBC-API.
  2. What is SERVLET API?
  3. The Java2D API
  4. Which two of the most important touch-based input technologies used
  5. List some of the important features of Mice & Keyboards
Next →
← Prev
Like/Subscribe us for latest updates     

About Dinesh Thakur
Dinesh ThakurDinesh Thakur holds an B.C.A, MCDBA, MCSD certifications. Dinesh authors the hugely popular Computer Notes blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps.

Dinesh Thakur is a Freelance Writer who helps different clients from all over the globe. Dinesh has written over 500+ blogs, 30+ eBooks, and 10000+ Posts for all types of clients.


For any type of query or something that you think is missing, please feel free to Contact us.


Primary Sidebar

Servlet Tutorials

Servlet Tutorials

  • Servlet - Home
  • Servlet - Types
  • Servlet - Advantages
  • Servlet - Container
  • Servlet - API
  • Servlet - Chaining
  • Servlet - Life Cycle
  • Servlet - Developement Way
  • Servlet - Servlet Vs CGI
  • Servlet - Server Side
  • Servlet - HttpServletRequest
  • Servlet - Cookies Advantages
  • Servlet - JDBC Architecture
  • Servlet - HttpServlet
  • Servlet - HttpServletResponse
  • Servlet - Web Technology
  • Servlet - Applet Communication
  • Servlet - Html Communication
  • Servlet - HTTP POST Request
  • Servlet - HTTP GET Request

Other Links

  • Servlet - PDF Version

Footer

Basic Course

  • Computer Fundamental
  • Computer Networking
  • Operating System
  • Database System
  • Computer Graphics
  • Management System
  • Software Engineering
  • Digital Electronics
  • Electronic Commerce
  • Compiler Design
  • Troubleshooting

Programming

  • Java Programming
  • Structured Query (SQL)
  • C Programming
  • C++ Programming
  • Visual Basic
  • Data Structures
  • Struts 2
  • Java Servlet
  • C# Programming
  • Basic Terms
  • Interviews

World Wide Web

  • Internet
  • Java Script
  • HTML Language
  • Cascading Style Sheet
  • Java Server Pages
  • Wordpress
  • PHP
  • Python Tutorial
  • AngularJS
  • Troubleshooting

 About Us |  Contact Us |  FAQ

Dinesh Thakur is a Technology Columinist and founder of Computer Notes.

Copyright © 2025. All Rights Reserved.

APPLY FOR ONLINE JOB IN BIGGEST CRYPTO COMPANIES
APPLY NOW