如何在javascript中设置JSTL变量值? [英] How to set the JSTL variable value in javascript?

查看:240
本文介绍了如何在javascript中设置JSTL变量值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在java脚本中设置JSTL变量值?

How to set the JSTL variable value in java script?

<script>

 function function1()

 { 

  var val1 = document.getElementById('userName').value;

  <c:set var="user" value=""/>  // how do i set val1 here?   

 }
 </script>

如何设置'用户'变量( JSTL )来自' val1 '的值( Java脚本)?

How do I set the 'user' variable (JSTL) value from 'val1' (Java script)?

推荐答案

这是不可能的,因为它们是在不同的环境中执行的(服务器端的JSP,客户端的JavaScript)。因此,它们不会按照您在代码中看到的顺序执行。

It is not possible because they are executed in different environments (JSP at server side, JavaScript at client side). So they are not executed in the sequence you see in your code.

var val1 = document.getElementById('userName').value; 

<c:set var="user" value=""/>  // how do i set val1 here? 

此处JSTL代码在服务器端执行,服务器将JavaScript / Html代码视为简单文本。来自JSTL代码(如果有)的生成内容将与您的其他JavaScript / HTML代码一起呈现在生成的HTML中。现在浏览器呈现HTML以及执行Javascript代码。现在请记住,浏览器没有可用的JSTL代码。

Here JSTL code is executed at server side and the server sees the JavaScript/Html codes as simple texts. The generated contents from JSTL code (if any) will be rendered in the resulting HTML along with your other JavaScript/HTML codes. Now the browser renders HTML along with executing the Javascript codes. Now remember there is no JSTL code available for the browser.

现在例如,

<script type="text/javascript">
<c:set var="message" value="Hello"/> 
var message = '<c:out value="${message}"/>';
</script>

现在浏览器会显示此内容,

Now for the browser, this content is rendered,

<script type="text/javascript">
var message = 'Hello';
</script>

希望这有帮助。

这篇关于如何在javascript中设置JSTL变量值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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