开发者

Javascript/JSP: How to pass JSP variables value on one page to javascript variables on next page? [duplicate]

This question already has answers here: Access Java / Servlet / JSP / JSTL / EL 开发者_如何学JAVAvariables in JavaScript (5 answers) Closed 6 years ago.

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?
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜