Reputation: 2989
I've a javascript variable which i need to pass as a parameter to the included file. Ex: var var1 = "test";
Now i need to pass this 'var1' to an include file like this
<%@include file="text.jsp?param1=" + var1 %>
Will this work ? Help me out.
Or, is there any other way around without submitting the form, I need to pass this variable data to that included file which is presented in the same jsp.
Upvotes: 1
Views: 175
Reputation: 38345
No, it won't work. Your JSP is compiled and run server-side, and the Javascript is executed much later on the client-side.
Upvotes: 1
Reputation: 6999
JS processed after JSP. Learn how server side and client side code is executed
Upvotes: 0
Reputation: 298818
No, this can't work, because the include will be parsed on the server side, long before the javascript var is available.
Instead, you need to add a request parameter to the page url:
<%@include file="text.jsp?param1=${request('someparam')}" %>
Upvotes: 2