JSTL in IntelliJ gives errors in JSP

2019-02-06 01:21发布

问题:

I'm playing with Google App Engine in IntelliJ. I'm trying to use JSTL tags in my JSPs. I've tried two different URIs I found on the internet, and both of them give me errors:

<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>

and

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

It reds out the URL and says it cannot resolve taglib. I've tried dropping different parts of the URL to see if Ctrl-Space gives me any autocomplete love, but no luck.

Any ideas what I need to do to make this work?

回答1:

Make sure that JSTL library jars are added to the module dependencies.



回答2:

Add something like this to your pom.xml under the <dependencies> node (you are using maven, right?):

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>2.5</version>
</dependency>

For gradle and other build systems see https://mvnrepository.com/artifact/javax.servlet/servlet-api/2.5

Also, make sure you pick a suitable version for your project. To see all available versions check here.



回答3:

In my case, I had to download the .jar from apache (https://tomcat.apache.org/taglibs/standard/) and add to my project dependencies.

File > Project Structure > Modules > Dependencies