I have a requirement where a form is present with first name, last name, file upload etc. File upload is done through ajax call and then the form is submitted to a servlet. I want to know whether the file has been uploaded or not in the servlet which is called after i click on the form submit button.
So is there any way i can read the response of the ajax call in the servlet ?
Servlets should be stateless, so if you upload a file through a servlet you should not expect the servlet to know about this when it processes the next request.
You have two options, upload the file and other parameters together in one request as shown in the tutorial here:http://docs.oracle.com/javaee/6/tutorial/doc/glraq.html
Upload the file and save it somewhere where the servlet will be able to query later, e.g database.
Thanks for the info.
posted 6 years ago
shanky raja wrote:Thanks for the info.
Hidden parameters go into request scope so you would need to send that value back to the page again so you can send it back with the second response. That would make the whole thing too chatty. Better store that value in session scope like suggested.
Also, what would that value be? I hope it's not some representation of the whole file because then you would be sending the file twice. You also wouldn't want to hold the whole file in memory (let alone session) unless they are really small files.
Too many men are afraid of being fools - Henry Ford. Foolish tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop