开发者

how to get full path from file type in JSP?

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.开发者_JS百科 My servlet code is like this:

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

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


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.


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/


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜