开发者

Passing script variables as parameters

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 tha开发者_如何学编程t included file which is presented in the same jsp.


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')}" %>


No, it won't work. Your JSP is compiled and run server-side, and the Javascript is executed much later on the client-side.


JS processed after JSP. Learn how server side and client side code is executed

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜