Java is not a language with training wheels. It is a language for professional programmers.

— Hebert Sheildt

File Uploading

The things that should be done before uploading are:

1. Set method=”post”
        This is mandatory as the default method is GET, which is capable of sending only textual data.

2. Set enctype="multipart/form-data"
        This tells that the form data will be having data of different types.

3. Couple of jar files.
        a.) commons-fileupload-1.2.2.jar
        b.) commons-io-2.4.jar

4. Create a folder where you want to store (here I am using the folder “images”) as below


 

Here is the registration page that I have developed. Click on the image to download source of the file.
Notice I have used the post method and ”enctype“ is also set.

Make sure that you add the above stated two “.jar” files in WEB-INF/lib folder, so that the container can locate them.

It is not a good idea to store images in the database as BLOB type, images should always be stored on the file system, and just the path/name of the image should be stored in the database.

The retrieval of images on the file system is much quicker than the retrieval from the database. As the retrieval from file system happens at OS level which is far quicker than the retrieval done from the DB.

There are other ways of uploading images, by using ZOOM API, it might return null for the text fields , for example if we use request.getParameter(“username”), it might return null, which we definitely dont want. But the classes in this tutorial allow you to get the actual parameter values and it won’t return null.

HTML Java

Click to download code.



© Copyright © 2013 SourabhBawage.com. All Rights Reserved.