We have already covered a tutorial for Dynamic file upload in Php, and as now we have also started covering JSP and Advanced Java in our Tutorials, so we made this script using JSP and Servlet too for the web developers who develop using JSP. In this Script we have used jQuery and Ajax for making the Upload Dynamic. We have also used Part Interface of Java.
We have used the NetBeans 7.0 IDE for developing this application, you can use any IDE which you want. You just need to make the JSP files, Servlets and Java Class enclosed in the Download File.
In this script we just have implemented how to upload file and preview it without refreshing the page. Database connectivity is not included, but you can very easily save the uploaded file's name into database by using a simple prepared statement to do that.
Apart from these two jsp pages you will have to make a Java package, in that package create a Java class file, named FileName.java and a servlet outside the model package named displayImage.java file.
Copy the content of Java Class file and servlet into these files respectively. Create a new folder for uploads, where the images/files will be uploaded and copy-paste its address in path variable in ajax_file.jsp file.