通过查看教程系列JSP, Servlets and JDBC for Beginners: Build a Database App on 乌德米,由Chad Darby完成,并在BalusC答案的帮助下,我用Intellij IDEA编写了以下代码
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%--To use JSTL core tags we need to import the following URL with prefix--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<%
// need to define a sample array
String cities[]={"City1","City2","City3","City4"};
// to use JSTL tags they have a to be a part of an attribute, either in the scope of the pageContext, session or application
pageContext.setAttribute("myCities",cities);
%>
<body>
<%-- for printing them in for each loop--%>
<c:forEach var="cityName" items="${myCities}" >
<%-- here we are using JSP expression language as ${...}}--%>
${cityName} <br/>
</c:forEach>
</body>
</html>并按照教程作者的建议(注意:教程是在JSTL上做的)和BalusC答案,在WEB-INF/lib下添加Eclipse IDE库。代码工作正常,但是IDEA编辑器给了我
无法用uri http://java.sun.com/jsp/jstl/core解析标签库
和
无法解析符号c:forEach
这些线条都是红色的,如图中所示。

为什么会发生这种事?在IDEA中还有其他地方可以添加这些库吗?提前感谢
发布于 2017-10-11 20:17:42
在使用基于spring的项目时,我收到了类似的消息。我通过在pom.xml中添加以下依赖项来解决这个问题
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>下一步,打开终端,然后执行maven干净安装。
mvn -U clean installhttps://stackoverflow.com/questions/44039706
复制相似问题