2009-08-17

java call javascript function from jsp ?

JSP/Java runs at the server side and produces a HTML page.
JS is part of the HTML page and runs at client side only.
JSP/Java and JS does not run synchronously.

To pass parameters from JSP/Java to JS you need to print it out as a
JS string variable so that JS can process it further when it runs.

E.g.<script>
var foo = '${somebean.someproperty}';
doSomething(foo);

var bar = '<%= somepagevariable %>';
doSomething(bar);
</script>

0 留言: