jsp 文件中的以下代码显示使用 Apache Tomcat 没有问题的网页:
<!DOCTYPE HTML>
<%@page import='java.util.*' %>
<%@page contentType='text/html' pageEncoding='UTF-8' %>
<html>
<body>
<%
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("string A");
stringList.add("string B");
for (int i = 0; i < stringList.size(); i++){
out.println("<p>"+stringList.get(i)+"</p>");
}
%>
</body>
</html>
但是这段使用 XML 语法的代码会抛出 JasperException,即使它与上面的相同,只是将 JSP 标记替换为 JSP XML 标记:
<!DOCTYPE HTML>
<jsp:directive.page import='java.util.*' />
<jsp:directive.page contentType='text/html' pageEncoding='UTF-8' />
<html>
<body>
<jsp:scriptlet>
ArrayList<String> stringList = new ArrayList<String>();
stringList.add("string A");
stringList.add("string B");
for (int i = 0; i < stringList.size(); i++){
out.println("<p>"+stringList.get(i)+"</p>");
}
</jsp:scriptlet>
</body>
</html>
引发此错误:
Aug 22, 2013 2:27:42 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Servlet.service() for servlet [jsp] in context with path [] threw exception [/cftp2Error.jsp (line: 6, column: 17) Unterminated <jsp:scriptlet> tag] with root cause
org.apache.jasper.JasperException: /cftp2Error.jsp (line: 6, column: 17) Unterminated <jsp:scriptlet> tag
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:42)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:408)
at org.apache.jasper.compiler.ErrorDispatcher.jspError(ErrorDispatcher.java:133)
...
谁能告诉我我的 XML JSP 代码哪里出错了?我正在使用 Tomcat 7.0.34 运行 JDK1.7。谢谢,基思