jstl里面的javascript [英] jstl inside javascript

查看:73
本文介绍了jstl里面的javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在javascript中使用jstl?

Is it possible to use jstl inside javascript?

我想要设置< c:set var =abcvalue =是/>

然后在html中访问此值并执行一些代码。我的问题是c:即使javascript条件为false,set也始终执行。

and then later access this value in html and execute some code. My problem is the c:set is executing always even if the javascript condition is false.

<script type="text/javascript">
var v1 = false;
<c:set var"abc" value="yes"/>

if(v1){
  <c:set var"abc" value="no"/>
}
</script>

在上面的代码中,即使v1为false,否设置为abc。

In the above code, even if v1 is false 'no' is setting to abc.

推荐答案

在谈论服务器端JSP解释时,在Javascript内部的想法没有任何意义。就域名而言,没有Javascript这样的东西。

There is no meaning to the idea of being "inside Javascript" when you're talking about server-side JSP interpretation. There's just no such thing as Javascript as far as that domain is concerned.

因此,是的,如果你的意思是想要做像

Thus, yes, it's possible, if you mean that you want to do something like

var something = '${abc}';

请注意,您必须小心引用和特殊字符。当您将JSP变量插入到将被浏览器解释为Javascript源的页面的一部分时,JSTL fn:escapeXml()函数是无用的。您可以使用JSON库对字符串进行编码,也可以编写自己的EL函数来执行此操作。

Note that you have to be careful with quoting and special characters. The JSTL fn:escapeXml() function is useless when you're interpolating a JSP variable into a part of the page that will be interpreted as Javascript source by the browser. You can either use a JSON library to encode your strings, or you can write your own EL function to do it.

这篇关于jstl里面的javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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