1

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 imagebelow

Why is this happening?. Is there any other place to add those libraries in IDEA? Thanks in advance

Community
  • 1
  • 1
Kasun Siyambalapitiya
  • 3,956
  • 8
  • 38
  • 58
  • 1
    See http://stackoverflow.com/a/32444393/104891. JSTL library seems to be missing from the dependencies. – CrazyCoder May 18 '17 at 13:06
  • @CrazyCoder Thanks, it removed the red colored lines. Do we need to do both in order for `JSTL` work on `IDEA` I mean adding libraries to `WEB-INF/lib` and adding the dependencies as you have suggested? – Kasun Siyambalapitiya May 18 '17 at 17:19
  • You just add the libraries to the dependencies and then these dependencies can be included into the artifact if your web container doesn't already provide them, otherwise you set the scope of the libraries to Provided and do not include them in the artifact. – CrazyCoder May 18 '17 at 18:24

1 Answers1

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