It's not a secret anymore!
The moose likes Java in General and the fly likes How do I retrieve a file path and file name? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "How do I retrieve a file path and file name?" Watch "How do I retrieve a file path and file name?" New topic
Author

How do I retrieve a file path and file name?

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 514
I need to send a file into a servlet through a web page. I would like to prompt the user with a file prompt. When the user browses to the file they need and hit OK, the file and path would be returned. Anyone have some idea how I might do this? Are there any APIs out there to do this?


By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Sara Tracy
Ranch Hand

Joined: Jan 06, 2006
Posts: 45
You could probably find some resources in Java Servlet & JSP cookbook - O'reilly. They have a chapter on file Uploading.
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
The Commons FileUpload Package may be good, too. I didn't think much of the code in the Jason Hunter package at O'Reilly.

Oh, and on the browser side, put something like this on a form:

[ January 11, 2006: Message edited by: Stan James ]

A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 514
Stan,

The browser side is what I'm mostly concerned with. Getting the file into the servlet is the least of my concerns. I'm mostly concerned w/the user having the ability to browse to the file and have the path and file name picked up by the file requester. Any solution for this?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

The HTML that Stan provided does that, doesn't it?
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 16479
    
    2

Oh, and by the way if you were thinking that your servlet just gets the path and file name, that isn't the way it works. The browser uploads the file name (and sometimes the path, but the servlet doesn't need it) and the contents of the file. The client side is actually the least of your concerns, processing file uploads is difficult. Unless you use the Commons FileUpload package that Stan linked to, in which case it's almost trivial.
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 514
Originally posted by Paul Clapham:
The HTML that Stan provided does that, doesn't it?


Yes it is. I honestly missed it. Looked at it quickly and thought it was ...

<input type='text' name='filename'>

not

<input type='file' name='filename'>
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 514
Originally posted by Paul Clapham:
...The client side is actually the least of your concerns, processing file uploads is difficult.


Agreed. I was actually looking for the tag to give me the file request. Before posting I was actually looking at Commons FileUpload Package.

Thanks for your help.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How do I retrieve a file path and file name?
 
Similar Threads
How to pass the path of the file to StreamSource class
PATH & CLASSPATH?
Array list help.
How download file from http in .bat file?
Invoking servlets in tomcat