You can't.
The variable has to be passed as part of a request.
JavaScript is client side. JSP and Servlet are server side.
Now, you can change variables in your JavaScript with JSP or Servlets, but you can't change a variable in JSP or Servlets with JavaScript.
Regards,
Nate