How can I access JSP variables from a JavaScript function in a JSP page?

Govind Seshadri

Answer by John Zukowski
Essentially, you can't. The JSP variable doesn't exist when the JavaScript is running as JSP runs in the server and JavaScript runs in the browser. Some servers though support server-side JavaScript. Read the FAQ for pointers on those.

Answer by Chilang Shen
Perhaps there is some way to do this.
1. If you only want to use the variable value once , you can embed the jsp tag inside your JavaScript segment such as:
<script language="JavaScript" >
var myvar;
myvar=<% =jspvar; %>

2. You can see the Resin project (www.caucho.com), which use JavaScript as a server side Script, but you can't use client side JavaScript access jsp variable directly!