0

Can we access a Java object array inside the JavaScript from JSP page.

We wanted to iterate the java object array on click using a JavaScript for that we required java object array from the jsp page. Is there any way to do this?

3
  • Does this answer your question? How to use scriptlet inside javascript Commented Jan 6, 2021 at 12:20
  • This is not possible. The JSP is executed on server side during generation of HTML. At the time the browser receive the HTML (with JavaScript included) the server request (the Java code) is finished. When the JavaScript is executed on the client side there are no Java objects. Don't be confused by the fact that the Java and JavaScript code are right next to each other in the same file. Commented Jan 6, 2021 at 13:45
  • You can either generate some JavaScript hash maps out of the Java object, so that it can be evaluated by the client side. Or you store the Java object inside the session and use Ajax to call the Java code via e.g. a servlet. Commented Jan 6, 2021 at 13:48

0

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.