var ans = prompt("...","");
String s = ans;
So to do what you want, you need to store the return of the prompt dialog to a hidden field and then submit the form.
Or you can append the entered data in the URL querystring while redirecting to a jsp page.
var ans = prompt("Enter something:","");
location.href="process.jsp?ans=" + escape(a);
and then in process.jsp, retrieve the url parameter and do the necessary action on it.
The actual implementation depends on what you really want to accomplish.