• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How do I retrieve a file path and file name?

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 45
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The HTML that Stan provided does that, doesn't it?
 
Paul Clapham
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic