问题描述
我有一些问题如下:
-
如何在JQUERY代码中使用JSP变量/数组?这里我们所拥有的JQUERY代码存储在单独的.js文件中,该文件包含在JSP文件中。
How can I use the JSP variable/array in JQUERY code? Here what ever the JQUERY code we have is stored in separate .js file and that file is included in the JSP file.
其实我想初始化JQUERY带有JSP变量的数组。
所以请指导我完成这项任务。
Actually I want to initialize the JQUERY array with the JSP variable.So please guide me to achieve this task.
推荐答案
在Plain Old JSP中
In Plain Old JSP
<script>
var someText = "<%= myBean.getText() %>";
</script>
使用EL(表达语言)
<script>
var someText = "${myBean.text}";
</script>
使用Struts
<script>
var someText = '<bean:write name="myBean" property="text" />';
</script>
使用JSTL
<script>
var someText = '<c:out value="${myBean.text}" />';
</script>
从本质上讲,可以从JSP填充Javascript对象。不要忘记,scriptlet和标签只是以HTML / XHTML的形式呈现,因此JS无法与标签对话,反之亦然。
In essence, it's possible to populate Javascript objects from JSP. Don't forget that scriptlets and tags are just rendered back as HTML/XHTML, so JS cannot talk to tags and vice-versa.
这篇关于是否可以使用jsp变量值来初始化JQUERY变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!