我正在尝试将 JSTL 用于我的 index.jsp 页面,但出于某种原因,每次将项目打包到 .war 并使用 Tomcat 运行后,都会出现以下错误:
HTTP Status 500 - /index.jsp (line: 12, column: 0) Unterminated <c:if tag
或
HTTP Status 500 - java.lang.ClassNotFoundException: org.apache.jsp.index_jsp
根据我在 google 上的发现,有两种方法可以将 JSTL 安装到您的 Maven 项目中: 1) 将此添加到 pom.xml
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
2) 向 WEB-INF/lib 添加一些 jar,但问题是:没有这样的文件夹是自动创建的,如果我手动创建它也没有帮助。项目结构如下所示:
index.jsp的代码如下:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
那么,我应该怎么做才能使这些工作正常进行?我找不到任何可以帮助我解决此问题的指南或信息。感谢您查看我的问题!
最佳答案
正如编译器告诉您的那样:未终止的 c:if 标记:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
查看您的 jsp 的第 4 行:
<title><c:if> Tag Example</title>
一定是
<title><c:if> Tag Example </c:if></title>
编辑:似乎我解释得不好,我已经在一个正在运行的网络应用程序中进行了测试,并且这种方式(这正是我试图解释的)有效:
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<html>
<head>
<title><c:if> Tag Example</title>
</head>
<body>
<c:set var="salary" scope="session" value="${2000*2}"/>
<c:if test="${salary > 2000}">
<p>My salary is: <c:out value="${salary}"/><p>
</c:if>
</body>
</html>
关于maven - 为 Maven (Intellij IDEA) 正确安装 JSTL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39087554/