views:

62

answers:

3

How do I get the file in a servlet running on Tomcat after using <input type="file"> in the JSP file?

A: 

Check this simple tutorial on jGuru. You have to use a MultipartHttpRequest and get the inputstream..

Teja Kantamneni
+2  A: 

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.

BalusC
+2  A: 

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