and in the servlet...">

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

+4
source share
3 answers

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.

+1
source

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/

+1
source

imagename contains the variable that you pass to the servlet ... the actual parameter of the HTTP request. If you want the full path, make sure that the program that calls your HTTP page passes the full path, not just the image name.

0
source

All Articles