Javascript functions get executed on the client side.
JSPs write the page (including the JS functions) on the server side.
As soon as the page is shown in the browser, all the
JSP functionality is done.
In your case, the sendRedirect is being called as soon as it's seen (the first load).
You can either implement this in Javascript document.location.url = ".." or something like that.
OR
You can implement it on the server by
testing to see if the the form has been submitted yet. If so, redirect. If not show the page.
In the top of your page: