简体   繁体   English

包括JSP文件在内的问题

[英]Issues including JSP file

Trying to learn JSP pages now and for some reason I can't get my code to execute. 现在尝试学习JSP页面,由于某种原因,我无法执行我的代码。 I'm trying to just call a function on the JSP page to update within a div. 我试图只在JSP页面上调用一个函数以在div中更新。 I have this running in Tomcat 8. 我已经在Tomcat 8中运行了它。

There are two files- One index.html and one test.jsp in the same directory. 在同一目录中有两个文件-一个index.html和一个test.jsp。 Below is the code for each file: 以下是每个文件的代码:

Index.html: Index.html:

<%@ include file="test.jsp" %>
<html>
<body>
<div id="mainContainer"></div>
<script language="javascript">
    updatePage("Test JSP test works!");
</script>
</body>
</html>

Test.jsp: Test.jsp:

<%!
updatePage(text) {
    var container = this.getElementById('mainContainer');

    container.html = "<h1>" + text + "</h1>";
}
%>

The div isn't getting updated and I just have a blank page. div没有更新,我只有一个空白页。 Why is my page not updating with the updated text? 为什么我的页面没有使用更新后的文本进行更新? Thanks. 谢谢。

The <%@ include... %> is a JSP directive and it can only be used inside a JSP page, not in a plain HTML page. <%@ include... %>是JSP指令,它只能在JSP页面内使用,不能在纯HTML页面中使用。 You should rename index.html to index.jsp if you want to do that. 如果要这样做,应将index.html重命名为index.jsp。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM