How do I get the file in a servlet running on Tomcat after using <input type="file">
in the JSP file?
Asked
Active
Viewed 1,582 times
0
-
disregard the jsp comment (this an html on the client...) – Eyal Aug 02 '10 at 17:34
-
You should use `edit` link to edit questions, not `add comment` link. – BalusC Aug 02 '10 at 17:42
3 Answers
2
If you're using Tomcat 6.0 or older, then use Apache Commons FileUpload. It's the defacto standard to parse file uploads in servlets. If you're using Tomcat 7.0 or newer with the fresh new Servlet 3.0 API, then use API-provided HttpServletRequest#getParts()
method.
Longer answer with detailed background information and code examples can be found here.
2
On the html side you define your form as multipart/formdata
<form class="sendform" method="POST" action="url.to.your.servlet" enctype="multipart/form-data">
...
<input type="file" name="sendfile" value="" />
</form>
on the serverside you can use fileupload from apache-commons

Nikolaus Gradwohl
- 19,708
- 3
- 45
- 61
0
Check this simple tutorial on jGuru. You have to use a MultipartHttpRequest and get the inputstream..

Teja Kantamneni
- 17,402
- 12
- 56
- 86