发布网友 发布时间:2022-04-21 04:29
共1个回答
热心网友 时间:2022-04-21 05:58
innerHtml 要插入的就是 HTML 代码,比如 <p>***</p> 这样的,所以你应该用 innerText。追答<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<%
application.setAttribute("words", "My Name is Java Web");
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome to Spring Web MVC project</title>
</head>
<body>
<p id="aa" style="text-align: center"></p>
</body>
<script>
document.getElementById("aa").innerText=
"<% if( application.getAttribute("words") != null ) out.print(application.getAttribute("words")); %>";
</script>
</html>
这段代码我电脑上没有问题: