what I understand is that you are trying to set the value of "test" when the onclick event is fired. When you first get to the jsp page all the scriptlets are processed at the server side and replaced by the constants, since the javascript method is not called on load of the form, the scriptlet is not processed
If this function is called when you click the button the value of
test will not be replaced by the scriptlet, it wud be a javascript error I suppose. So in order to overcome this what you can do is rewrite your javascript code in this way
So now the testVal variable is initialised when the page is loaded and when you click the button it gets the value there.
Hope this is what you were trying to do.