Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 887367
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T13:13:06+00:00 2026-05-15T13:13:06+00:00

Imagine this simple form for uploading a file: <form action=upload enctype=multipart/form-data> <input type=text name=name/>

  • 0

Imagine this simple form for uploading a file:

<form action="upload" enctype="multipart/form-data">
    <input type="text" name="name"/>
    <input type="file" name="file"/>
    <input type="submit"/>
</form>

If there is some error (can’t copy file, name is not correct…) submitting the form, it must return to the same page, but the file I’ve selected will be lost. In a large form with several fields that must be validated server side can be very annoying if the user have to select files every time.

Thinking about it, I’ve find a couple of possible solutions:

  • Submit form as an ajax request, then go to the next page only if validation is correct. The problem is I must implement something to put every validation error in its place instead of using MVC’s features (Spring MVC form tags, in my case).

  • Submit form. If there is an error, send a page with a “history.back()” in javascript. My file will be there again, but I have no easy way to show validation messages.

I think both solutions are very very clumsy. But selecting the files every time there is a validation error isn’t a good solution too.

What do you think? Which solution is better? Is there any good one (preferably without javascript)?

Thanks.

Note: I’m using Spring MVC 3

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T13:13:07+00:00Added an answer on May 15, 2026 at 1:13 pm

    It’s true that the file field will be lost since there’s no way to prefill the input type="file" field in HTML. This is a security restriction to avoid jokers with forms like this:

    <form name="upload" action="upload" method="post" enctype="multipart/form-data">
        <input type="file" value="c:/passwords.txt"><input type="submit">
    </form>
    <script>document.upload.submit()</script>
    

    Your only resort is to submit the form in the background so that the page with the original form stays open. In other words: Ajax. There are several JavaScript libraries available for this task, for example jQuery Form plugin. It’s then basically as easy as

    $('#formId').ajaxForm();
    

    (yes, it will work with file uploads as well, this plugin transparently goes to “iframe mode” then)

    But since you’re using Spring MVC which doesn’t support ajaxical requests out of the box, you’ll have to create a custom ViewResolver in the server side to let it seamlessly work with ajaxical stuff. You can find here a nice blog which describes that in detail.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Imagine this simple form <form action=<?php echo $_SERVER['REQUEST_URI']; ?> method=post> <fieldset> <legend>Contact Me</legend> <label
I've got this HTML form where I have multiple input elements: text, radio, and
I imagine this has a rather simple answer <% for user in @users %>
I've never learnt JavaScript, but I imagine this is quite a simple problem. Just
Imagine a simple case like this: class Book has_many :chapters end Let's say in
Good day stackoverflow 'ers I'm doing a simple AJAX form, imagine some kind of
Just imagine this simple situation: int temperature = 20; is there any possibility to
I got my little html fisher working and it grabs a text file form
Imagine the scenario of a contact form, whereby data is to be collected and
Imagine this simple piece of code: class Constructor() { var string: String = _

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.