javascript 访问jsp页面的javascript中的表达式语言

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19318674/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-27 15:09:06  来源:igfitidea点击:

Accessing the expression language in javascript of a jsp page

javascriptjspel

提问by reddy

I have a "jsp" file. In that file I have "Javascript" scripting. Within <script>tags,only javascript is allowed but, how is "Expression Language" executed?

我有一个“jsp”文件。在那个文件中,我有“Javascript”脚本。在<script>标签内,只允许使用 javascript 但是,“表达式语言”是如何执行的?

<body>
    <script type="text/javascript">
        var b=${requestScope.name};
    </script>
</body>

采纳答案by seedi

Executed.

执行。

As "Expression Language" is executed on the server side the statement

由于“表达式语言”在服务器端执行,语句

${requestScope.name} 

executed at server side and its value is available to JavaScript at client side. now at the client side the line becomes

在服务器端执行,它的值在客户端对 JavaScript 可用。现在在客户端,线路变成

var b='corresponding expression language executed value';

回答by uneakharsh

bring that variable from request scope to page scope,

将该变量从请求范围带到页面范围,

<c:set var="myVar" value="${request.myVar}" />

after this you can try this :

在此之后你可以试试这个:

<script>
    var myVar= '${myVar}' ;
</script>

Though I am not sure if it's the best approach; but this should do.

虽然我不确定这是否是最好的方法;但这应该可以。

回答by R. Oosterholt

JSP is server side. You cannot access the script variables. These variables are only executed client-side.

JSP 是服务器端。您无法访问脚本变量。这些变量仅在客户端执行。