212 File Uploading and downloading java web application servlet tutorial

Published: 05 June 2020
on channel: tech fort
3,041
22

#File Uploading & Downloading:
==============================

Sending a file from local system to server machine system is called as file uploading

While developing application for educational, matrimonial, we need to add file uploading and downloading facility to application.

To perform file uploading through servlet programming we need to use Java Zoom API support.

We can download API related jar files from :
http://www.javazoom.net/jzservlets/up...

1) uploadbean.jar (main jar file)
2) cos.jar (Dependent jar file for uploadbean.jar file)
3) struts.jar (Dependent jar file for uploadbean.jar file)

Since the classes and interfaces of uploadbean.jar are using the classes of & interfaces of cos.jar, struts.jar files, so we can say cos.jar, struts.jar files are dependent .jar files to uploadbean.jar

form page can supply file uploading component to end user to select files from client machine filesystem.

Select File : input type="file" name="f1"

While performing file uploading :
1) Make form page sending "POST" methodology based request
2) Specify enctype="multipart/form-data" in form tag.
multipart/form-data: gives instruction to server that this form page sends multiple types of data along with request(like audio, image, video, txt, etc...)

Java Web Application to perform file uploading & Downloading:
------------------------------------------------------------
Deployment Directory structure:

65UpDownLoadWebApp:
----------------
|----------upload1.html
|----------WEB-INF
|----------web.xml
|----------lib
|----------cos.jar
|----------struts.jar
|----------uploadbean.jar
|----------classes
|----------UplSrv1.java and .class

add *.jar to libraries

Run , Test the web application:
Request URL:
http://localhost:2020/UpDownLoadWebApp/upload1.html

jar files in classpath:
1) servlet-api.jar 2) uploadbean.jar

NOTE: When web resource programs of java web application uses third party API(like java-zoom API) then third party API related main jar file should be added to classpath as well as main, dependent .jar files should be added to WEB-INF/lib directory of web application.




File Downloading:

Sending the content/file from server machine to client machine file system is called as file downloading.

There are 2 types of file downloading.
1) Response downloading
Here repsonse of web resource program(like servlet/jsp program)
Gives to client as downloadable file.

2) Resource downloading
Here the files kept in server machine file system, and those file system goes to client as downloadable file.
Ex: donwloading a software, songs, video file etc..

There is no need to work with any third party API like javaZoom API to perform file downloading.

Just we need to Add the following two lines of code in any servlet program or JSP Program to make its response as downloadable file.

response.addHeader("Content-Disposition","attachment:filename=title.doc");
*1 *2 *3
response.setContentType("application/msword");
*4

*1(Content-Disposition)- Special resource header that gives instructions to server towards sending response/output to the client.

*2(attachment)- Gives instruction to server the response of current program must go to client as downloadable file.

*3(filename=title.doc)- Name of default file that is going to hold reponse of web resource program.

*4(application/msword)- Response content type.


On this page of the site you can watch the video online 212 File Uploading and downloading java web application servlet tutorial with a duration of hours minute second in good quality, which was uploaded by the user tech fort 05 June 2020, share the link with friends and acquaintances, this video has already been watched 3,041 times on youtube and it was liked by 22 viewers. Enjoy your viewing!