• Post Reply Bookmark Topic Watch Topic
  • New Topic

How do I retrieve a file path and file name?  RSS feed

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Sara Tracy
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTML that Stan provided does that, doesn't it?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 515
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!