如何使用javascript使用请求中的属性

How to use attributes from request with javascript?

本文关键字:属性 请求 何使用 javascript      更新时间:2023-09-26

为什么警报框不起作用?

<script>
<% Player player = (Player) request.getAttribute("player"); %>
alert(<%=player.getTempId()%>);
</script>

我猜函数会返回一个字符串。试试这个:

alert("<%=player.getTempId()%>");

因为如果返回一个没有引号的字符串,您将获得呈现以下内容的页面:

alert(aString) //and then you'll get an error that aString is not defined. 

通过添加",页面将呈现如下:

alert("aString") //and will work