Accessing the expression language in javascript of a jsp page

我只是一个虾纸丫 提交于 2019-12-10 14:44:32

问题


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?

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

回答1:


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

var b='corresponding expression language executed value';



回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/19318674/accessing-the-expression-language-in-javascript-of-a-jsp-page

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!