Re: Post HTML5, Javascript & CSS3 queries here
One thing noticed that the XML file had wrong version of apache listed in the code so I fixed that.
Now when I click on upload button, I'm still getting that null error.
So I ran the fileupload.jsp page on browser and came to know that i'm getting nullpointerexception error (I know its very vague...)
Piyush, what you've posted here is a JSP (Java Server Pages) request handler. The XML is nothing but a deployment descriptor. These are standard J2EE components.
You are actually asking Java in an html thread.
Do you have J2EE knowledge? I figure that's why you are having problems in deciphering the issues.
Anyways, i'll help you. I tested the code in my machine, and it works just fine. That is, i'm able to upload files into the required directory, of my choice.
I assume you are using the apache tomcat webserver/J2EE container
Here's what you should do:
1.All those files you sent, should reside inside the server directory. You apache directory should contain sub directories like bin, webapps,etc.
2.Copy the files inside the webapps folder, and create another folder inside it, which will be the main application folder.Inside that, create another directory called "WEB-INF".
3.Now copy the "upload.jsp" and "file_upload.html" inside the main application folder (not WEB-INF) and copy the xml file (name that web.xml and not webapp.xml) inside the WEB-INF folder.
4.Now comes the important part. Your JSP file has "apache common" import statements, but the application is not able to find those libraries. The DiskFileItemFactory is a class that extends Object
and implements ServletFileUpload. Standard java terms. So you want to include those libraries inside the server's "lib" directory.
5.Download the Jar files
here and
here and extract them into the "lib" folder in server.
6.Open the web.xml and give proper path in the <context-param></context-param> i.e where exactly you want to save the uploaded file.
7. Restart the webserver and it should work now.
P.S - Remember, don't access the file_upload.html by just clicking on it. It will be static. After starting the webserver, access the html, through server URL eg. localhost:8080/xyz/abc/file_upload.html(directory path of file location). It will work.