将变量从 JSP 传递给 Javascript [英] Passing variable from JSP to Javascript

查看:37
本文介绍了将变量从 JSP 传递给 Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道已经有这方面的问题,但我不能简单地完成这项工作,我有一个带有 java 变量的 JSP 文件:

I know there is already questions about that, but I just can´t simply get this work, I have a JSP file with a java variable in it:

String test = "Hello";

我需要在嵌入在同一个 JSP 文件中的 Javascript 中读取这个值,我尝试了很多选项,但它不起作用,为了安全起见,我不想使用 URL 或隐藏值传递值.

And I need to read this value in the Javascript embedded in the same JSP file, I tried so many options, but it is not working, and for security I don't want pass the value using the URL or hidden values.

关于如何让它工作的任何想法?

Any ideas of how get this working?

推荐答案

最好的方法是在你的 javascript 代码中使用如下内容;

The best way to do it is to use something like following in your javascript code;

var myvar = '${jspvar}';

这篇关于将变量从 JSP 传递给 Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆