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

3,749 questions

4,049 answers


10,705 users

How to upload files to server using JSP/Servlet?

0 votes
asked 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" />
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 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 by sara Guru (24,570 points)

Related questions

0 votes
1 answer 11 views
0 votes
1 answer 116 views
0 votes
2 answers 49 views
0 votes
1 answer 18 views
18 views asked by smith Geek (15,340 points)
0 votes
1 answer 14 views
14 views asked by sara Guru (24,570 points)