You seem very confused about what happens on the client versus what happens on the server. Java code runs on the server to generate the page in the first place (assuming you are using
servlets and
JSP), and when the form is submitted to a servlet. JavaScript runs on the client.
So what it is it you are actually trying to accomplish and when?