1

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.

3 Answers 3

2

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')}" %>
Sign up to request clarification or add additional context in comments.

3 Comments

I've that script variable data in the same page which I need further in the included file in the request object.
@Sririam still, it's not there on the server, only on the client. It won't work.
here, the whole content of file is treated as URL to the file name. Did it work at your side to statically pass parameters to the included file?
1

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

Comments

0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.