Possible Duplicate:
How to upload files to server using JSP/Servlet?
I wrote this code in jsp to send a file to a Servlet:
<input type="file" name="inputFoto" id="inputFoto"/>
and my Servlet is:
{...
File fotoImg = (File) request.getAttribute("inputFoto");
byte[] foto = convertiInArrayByte(fotoImg);
..}
It does not work. How can I get a file in a Servlet from a JSP?
Can someone help me? Maybe there are some problems with the path of the file (on my pc)!?!?
filetype of inputs are not simple attributes, they are sent in separate chunk of the request. Therefore you must have at least 2 parts in your HTTP request.So, you must use
Multipart Form Dataprocessing to parse the file. There are a number of examples here, for example:Most commonly the Apache Commons Fileupload http://commons.apache.org/fileupload is used for this.