C Books Guide and List
C++ Books Guide and List
Best Java Books

3,749 questions

4,049 answers

114 comments

10,705 users

How to upload files to server using JSP/Servlet?

0 votes
21 views
asked Jan 20, 2014 by john Guru (27,140 points)

2 Answers

0 votes
To browse and select a file for upload you need a HTML <input type="file"> field in the form.

As stated in the HTML specification you have to use the POST method and the enctype attribute of the

form has to be set to "multipart/form-data".

<form action="upload" method="post" enctype="multipart/form-data">
    <input type="text" name="description" />
    <input type="file" name="file" />
    <input type="submit" />
</form>
After submitting such a form, the binary multipart form data is available in the request body in a different format than when the enctype isn't set.
Before Servlet 3.0, the Servlet API didn't natively support multipart/form-data. It supports only the
default form enctype of application/x-www-form-urlencoded. The request.getParameter() and consorts
would all return null when using multipart form data.
answered Jan 20, 2014 by smith Geek (15,340 points)
0 votes
You need the common-io.1.4.jar file to be included in your lib directory, or if you're working in any  editor, like NetBeans, then you need to go to project properties and just add the JAR file and you will  be done.
 
To get the common.io.jar file just google it or just go to the Apache Tomcat website where you get the  option for a free download of this file. But remember one thing: download the binary ZIP file if you're  a Windows user.
 
 
 
answered Jan 20, 2014 by sara Guru (24,570 points)

Related questions

0 votes
1 answer 10 views
10 views asked Jan 3, 2014 by sara Guru (24,570 points)
0 votes
1 answer 113 views
0 votes
2 answers 48 views
48 views asked Jan 21, 2014 by john Guru (27,140 points)
0 votes
1 answer 18 views
18 views asked Jan 3, 2014 by smith Geek (15,340 points)
0 votes
1 answer 12 views
12 views asked Jan 3, 2014 by sara Guru (24,570 points)
...