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?

  • Does this answer your question? [How to use scriptlet inside javascript](https://stackoverflow.com/questions/5158400/how-to-use-scriptlet-inside-javascript) – Traian GEICU Jan 06 '21 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. – vanje Jan 06 '21 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. – vanje Jan 06 '21 at 13:48

0 Answers0