One solution for JSP data and JavaScirpt data interaction

zhaozj2021-02-08  232

One solution for JSP data and JavaScirpt data interaction

For web programs, the front end (JAVAScript) and the backend (JSP / servlet) can not share data, only the backend program (JSP) outputs the data, generates the page to the front end, at this time there is a page JavaScript code is likely to get the so-called JSP data. Similarly, JavaScript data can be obtained in the JSP program only if the data in JavaScript is submitted to the backend JSP code.

How to implement the data in JSP in JavaScript in the page or JavaScript data that uses the page in JSP?

First, the data of JavaScript in the page is submitted to the jsp program to the background 1 can pass the JavaScript data to the JSP program in the form of xxx.jsp? Var1 = aaa & var2 = bbb, and use <% in JSP at this time String strvar1 = request.getParameter ("var1");%> You can get the data passed by the JavaScript script; 2 Use JavaScript to send the data to the JSP program by adding hidden domain information in the form, then use the form commit to the JSP program. Refer to the following script: