问题
By looking at the tutorial series JSP, Servlets and JDBC for Beginners: Build a Database App on Udemy done by Chad Darby and with the help of BalusC answer I wrote the following code in 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>
and add the JSTL libs under WEB-INF/lib as suggested by both the author of the tutorial (note: tutorial is done on Eclipse IDE) and BalusC answer. The code works fine, but IDEA editor give me
cannot resolve taglib with uri http://java.sun.com/jsp/jstl/core
and
cannot resolve symbol 'c:forEach'
and those lines are in red color as seen in the image
Why is this happening?. Is there any other place to add those libraries in IDEA? Thanks in advance
回答1:
I got similar kind of message while working with spring based project. I resolved it by adding following dependencies inside 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>
next open terminal and then do maven clean install
mvn -U clean install
来源:https://stackoverflow.com/questions/44039706/cannot-resolve-taglib-with-uri-in-intellij-idea