I am working on a struts 2 web application where user can upload file through a file upload form, if the file already exists in database, a confirmation message should be displayed to overwrite the existing file or cancel the action.
On upload the database is queried for that file and if it exists the action results and set a flag in session which shows the jquery dialog box for user confirmation. I need to implement continue button in the dialog box which will set another flag to specify overwrite and call the same action again, this time the file will be uploaded. To implement this I need to prefill the file upload input box with previous request parameter before calling the upload action.
Is there any other method to implement the above requirement?
Please let me know in case any details are required.
Thanks in advance.
I assume that you dont want to upload a file if a file with same filename exists in the database. If this is the case, why dont you check for the duplicity of filenames as soon as a file is selected to upload. This can be done in two ways
You can use the
onchangeevent of thefileelementFor security reasons, you cannot mess with the
valueattribute of thefileelement programatically, otherwise you could fill-in any file from the user’s system and submit the form