How to Pass JavaScript Values to Scriptlet in Jsp

How do I pass JavaScript values to Scriptlet in JSP?

Your javascript values are client-side, your scriptlet is running server-side. So if you want to use your javascript variables in a scriptlet, you will need to submit them.

To achieve this, either store them in input fields and submit a form, or perform an ajax request. I suggest you look into JQuery for this.

how to pass Javascript variable in Scriptlet

Scriptlet is executed before any data about webpage get sent from server to client. Whatever you want to do you need to send postback to server (with forms or ajax call). I usually use jQuery so my answer will use it but feel free to modify it to use native JS code. First, I would create a page on server called createJsonObject, call it from client with $.ajax (type: "POST")and passed my two arguments as object {repoId: repoId, repoName: repoName}. On server I would place my JSP on that page, read argumants upon page load, execute function and return object with data to client. In .done() I would do something with that data (display them in form, save them in JS variables...). Hope this helps.

how to use javascript variable inside scriptlet tag

This question and answers may help you. It was asked by me earlier today :)

Javascript variable in asp block code

Good luck!



Related Topics



Leave a reply



Submit