How to get the full path of a file type in JSP?
I wrote some code in JSP like this -
<input type="file" name="imagename" > and in the servlet I get the value "imagename". But it gives the name of the image instead of the full path. My servlet code is as follows:
String imagename = request.getParameter("imagename"); and i don't want to use javascript. any ideas? thanks in advance
Perhaps you should check this question: How to get file path from HTML input form in Firefox 3
There are few reasons why a server should know the full path to a file. If you want to download the file, you will need to use the appropriate library, for example Apache Commons FileUpload and transfer the file using.
<form action="upload-script-url" method="post" enctype="multipart/form-data"> <input type="file" name="file"> <input type="submit"> </form> Apache Commons FileUpload will then accept and convert the encoded file into a usable form.
Otherwise, you will need to use JavaScript to get this path.
Assuming that you are trying to upload a file to your server, please note that downloading files is a bit more than what you are trying to do - do not expect that if you have the input type "file" in the form, when you submit the file, it just reaches your rank, without any effort. There is a certain procedure for this.
This article may be a good link: http://www.cs.tut.fi/~jkorpela/forms/file.html
For Java, use Apache commons-fileupload: http://commons.apache.org/fileupload/