Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

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
 
reply
    Bookmark Topic Watch Topic
  • New Topic