Javascript/JSP: How to pass JSP variables value on one page to javascript variables on next page? [duplicate]
Currently I am trying to send JSP value to javascript. Is it possible? My cases is as follows:
On Page abc.jsp, user enters data in form. Which is send on the next page xyz.jsp. I want to use this data in xyz.jsp pages javascript. Is it possible? Is yes how to do this?
also would like to know, if I auto refresh this page(or part of page) ie xyz.jsp then is it possible without javascript failing or crashing?
Thanks.
Just let JSP print it as if it is a JS variable. Assuming that you've variable ${foo}
in JSP:
<script>var foo = '${foo}';</script>
This will end up in webbrowser as
<script>var foo = 'somevalue';</script>
Keep in mind: JSP runs at webserver and produces HTML. JS is part of HTML and runs at webbrowser.
See also:
- How to communicate between JavaScript and Java/JSP/JSF?
精彩评论