4

i written some code in JSP like this--

<input type="file" name="imagename" >

and in servlet i am retrieving 'imagename' value. But it is giving the name of the image instead of full path. My servlet code is like this:

String imagename = request.getParameter("imagename");

and i dont want to use javascript. any ideas? Thanks in advance

JoseK
  • 31,141
  • 14
  • 104
  • 131
janasainik
  • 811
  • 5
  • 20
  • 40
  • it seems you are posting some parameter named `imagename` from your code, and you are trying to find path of that parameter ?? confusing, Or if you are uploading the file and you want the path to file from client???? – jmj Dec 03 '10 at 10:45
  • There is an error in your text. You say `I've written some code in JSP like this:` and then there isn't a code sample. Did you try using the upload HTML element to get the result? – Daniel Fath Dec 03 '10 at 10:46
  • my jsp code was missing tyhere. the code is: – janasainik Dec 03 '10 at 10:47
  • I think, it is not possible to get the full path without using Javascript from client. – Mohamed Saligh Dec 03 '10 at 10:50

3 Answers3

1

Assuming that you are trying to upload a file to your server, please note that file uploads are a little more than what you are trying to do - do not expect that if you have a "file" input type in a form, on submission the file just reaches your sever, with no effort. There is a certain procedure to do that.

This article might e a good reference : http://www.cs.tut.fi/~jkorpela/forms/file.html

For Java, use Apache's commons-fileupload : http://commons.apache.org/fileupload/

madhurtanwani
  • 1,199
  • 7
  • 13
1

Maybe you should checkout this question: How to get the file path from HTML input form in Firefox 3

There is little to no reason why server should have to know full file path. If you want to upload a file, you'll need to use an appropriate library like 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 transform encoded file into a usable form.

Otherwise you'll need to use JavaScript to get that path.

Community
  • 1
  • 1
Daniel Fath
  • 16,453
  • 7
  • 47
  • 82
0

imagename contains the variable you pass to the servlet... the actual HTTP request parameter. If you want the full path, be sure that the program that is calling your HTTP page is passing the full path instead of just the image name.

Luca Matteis
  • 29,161
  • 19
  • 114
  • 169