在JavaScript中获取servlet上下文

t

在我的jsp中,我使用 <%String base = (String)application.getAttribute("base");%>

我试图在JavaScript中使用“ base”,但无法正常工作。以下是我的JavaScript:

<script>
    var newBase = <%=base%>;
</script>

有人可以帮我解决这个问题吗?

桑托什

您可以这样尝试,

将值设置为hidden

input type="hidden" id="hidVal" name="txt2" value="${base}"/>

在您的Java脚本中,

<script>
var x = document.getElementById('hidVal').value;
alert(x);
</script>

更新

var newBase = '<%=base%>';

您缺少将这些值视为string的引号。

希望这可以帮助 !!

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章