• 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
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

Filename selection window

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have a jsp form in which I want the user to enter a fully qualified filename (to later link to). But it would be better to pop up the file select window and let them select the file.

Any ideas?
I assume if I'm doing jsp's I don't want to get into Swing too.

Thanks,
Dana
 
DK Taylor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OK, the easiest answer is best. I can say <INPUT type=file> and get a browser window which returns a filename

Dana
 
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Unless there's some other option to the "type=file" input element that I'm not aware of, this input field allows the user to select a file, but the contents of the file are sent to the server -- not the path to the file.

This is how webmail sites implement attachments. The server gets the contents of each file as part of the HTTP request using the POST method.
 
DK Taylor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
David,
I tried it, and what I get back in the response is just what I typed:
'c:\abc.txt'. Which is what I want.

Thanks,
Dana
[ May 02, 2005: Message edited by: DK Taylor ]
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm, looking at the [url=]RFC for form submission[/url] I note that there are two other requirements for file upload: setting the form encoding type attribute to "multipart/form-data" and setting the form submission method to "post". I suppose if you don't do both of those, the client can't possibly send the file's contents, so it just sends the name. Cool.
 
DK Taylor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, David. I am copying your reply, because I DO want to actually upload the file.

I've been thinking about the design. This is a Problem Reporting app, which will allow you to "attach" documents. But then do you copy them to the server, which "locks" it in, or link to an editable document? Sometimes its good to freeze it and sometimes not. So I plan to have a button to "save" the file.

Thanks again, and Take care,
Dana
 
David Harkness
Ranch Hand
Posts: 1646
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd definitely recommend storing a copy on the server to keep everyone honest. Allow them to upload new versions for history tracking, and they'll love you.

Are the path to the file and its name valuable information beyond allowing you to grab a copy of it? Or is it sufficient to just get the contents? As a compromise you could have an edit box for "title" so they're not constrained to valid file name formats. Again, it all depends on your needs.

There are pre-built tools to handle the uploaded content, for example Jakarta's FileUpload (probably part of Commons Net, I'd guess). I coded my own way back when but haven't needed to handle uploaded files since. I do know it's not so simple. You get a stream and don't get told the size of the file up-front. The early tools simply wrote the data to a temporary file and returned it to your application. You can double-check, but when you get the file's contents, you don't get its name.

Then again, maybe the latest versions of Struts abstract this all out of sight for you. Wouldn't that be nice?

Be sure to share your pain with us when you hit that part.
 
DK Taylor
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'd definitely recommend storing a copy on the server to keep everyone honest. Allow them to upload new versions for history tracking, and they'll love you.


That's a good alternative.


Are the path to the file and its name valuable information beyond allowing you to grab a copy of it? Or is it sufficient to just get the contents?


I was thinking I would copy the file to my own name (like user_date_seq_description). The form has a description and the link. So I would display the description and retrieve from that.


There are pre-built tools to handle the uploaded content, for example Jakarta's FileUpload (probably part of Commons Net, I'd guess). I coded my own way back when but haven't needed to handle uploaded files since. I do know it's not so simple. You get a stream and don't get told the size of the file up-front. The early tools simply wrote the data to a temporary file and returned it to your application. You can double-check, but when you get the file's contents, you don't get its name.


?? I have the file's name, and I figured I would just read it and write it (probably in binary) until it was done. Am I missing something?


Then again, maybe the latest versions of Struts abstract this all out of sight for you. Wouldn't that be nice?


It would if I were using Struts.
This is a learning exercise. I have learned Java, JSP, Servlets, WSAD, JUnit & Ant. Maybe later.

Thanks,
Dana
 
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic