I'm using a HTML form to allow a user to upload some files to a java servlet and start some analysis. When the user clicks submit I use a javascript function to do some quick validation on the form i.e. have they selected the right options, entered a valid email etc.
The form data is then passed to the doPost()
method in my servlet where I do some more complex checking for errors in the input data. After this the user is either forwarded to an error page or notified that the job has been started.
What I would like to do is display a progress page while the error checking is taking place in the servlet. It seems I can't forward the user to the progress page in the servlet as this commits the response and I can't carry on the checking and then later forward the user to the relevant page. This is explained here.
I think the answer might be to display the progress page when the user clicks the submit button and before the form data is sent to the servlet. This could be done in the javascript validation in the form. So far my attempts at this have failed. I think I'm misunderstanding something!
I've tried the advice listed here to use window.location.replace(...)
but it doesn't seem to work. I've also tried using a button instead of a submit input type and defining the form action in the javascript as shown here.
My javascript validation function is
<script language="JavaScript">
<!-- // ignore if non JS browser
function Validator(form) {
var error = "";
if (form.family.value == "") {
error += "Please upload a family file\n";
}
if (error != "") {
alert(error);
return (false);
} else {
window.location.replace("http://stackoverflow.com");
return (true);
}
}
and my form is submitted using <form method="POST" enctype="multipart/form-data" action="runDupliPHY.do" onsubmit="return Validator(this);">
from a submit input.
Any examples of how to show a progress page before submitting the form so the user sees the progress page while the servlet processes the form data would be great.