为 Maven (Intellij IDEA) 正确安装 JSTL

Proper installation of JSTL for Maven (Intellij IDEA)

我正在尝试将 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) 添加一些 jar 到 WEB-INF/lib,但问题是:没有自动创建这样的文件夹,如果我手动创建它也没有帮助。项目结构如下所示:

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>&lt;c:if&gt;  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>