• 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

File upload problem

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am using struts and have an upload.jsp and its associated UploadForm.java and UploadAction.java. The jsp's form has an enctype=multipart/form-data and contains an html:file field to upload a file as well as a bunch of text fields for metadata associated with the file. If an error occurs during validation, the struts controller servlet forwards to the same jsp with error messages. The problem is that the filepath the user specified is no longer present. Is there a way to restore this value so the user doesn't have to complete this field again (the other text fields remain filled in).
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rajeev Ja:
Is there a way to restore this value so the user doesn't have to complete this field again?


No, there isn't.

None of the major browsers will allow a default for an upload file field to be set from the server-side. It's a security issue. Think about it: If the browser allowed a default value in this field, what would prevent a malicious website from defaulting the most likely path to your outlook file with all your names and addresses, and using JavaScript to submit the form before you even knew what was happening?

One possible work-around would be to use JavaScript to validate the other fields before the form is submitted.
[ December 18, 2007: Message edited by: Merrill Higginson ]
 
Rajeev Ja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Instead of validation If i have other button on click of that it will go the action class and all other field values are restored except the browse button file path how to resolve this
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The fact is that once a form is submitted, there is no way to redisplay the <html:file> field with its original contents because of the security issue that I mentioned in my last post. Whatever solution you devise must take into account this fact.

One possible solution would be to make an AJAX call to the server without submitting the form.
 
Rajeev Ja
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No I do not want to use Ajax can any one tell a solution
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic