23

First of all my JSTl code works on my server because i have the proper Jar file in the Lib folder in tomcat7. This is just really an IDEA problem. My questions comes down to where i put the same jar file in my file directory within IntelliJ.

I have ran into a error in IntelliJ and JSTL.

My problem is that when i use

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

It results in Cannot resolve taglib with uri. I have tried different Jar files and I do know that i have to correct version for my servlet.

Im running tomcat7 on Ubuntu Server 15.04, and IntelliJ 14.1.3.

I have tried importing the jar file though the Project Structure, and including it in various places but still the same error after re-building the project, and closing down and reopening the IDEA.

This sample code runs when deployed to tomcat but IntelliJ keeps giving errors.

<table border="1">
    <c:forEach var="a" items="${data}">
        <tr>
            <td>${a}</td>
        </tr>
    </c:forEach>
</table>

<c:forEach begin="0" end="255" var="i">
    <span style='color:rgb(
        <c:out value="${i}"/>,
        <c:out value="${i}"/>,
        <c:out value="${i}"/>);'>
        <c:out value="${i}"/></span> <br />
</c:forEach>

I would like to know how to stop IntelliJ from giving errors on my Syntax even though the code works.

I have read JSTL in IntelliJ gives errors in JSP

and

https://www.jetbrains.com/idea/features/jsp_editor.html

Still no luck.

Community
  • 1
  • 1
dsadnick
  • 624
  • 1
  • 7
  • 25

6 Answers6

77

First add this to the top of your .jsp file:

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

It will still give syntax error but you can fix that by adding javax.servlet:jstl:1.2 as a module dependency. To do that, follow these steps:

  1. Click your project name and press F4 to bring up the module settings dialog.
  2. Then go to the dependencies tab in the modules section.
  3. Click the green + icon library From Maven.
  4. Search for javax.servlet:jstl:1.2 in the search bar and press OK and it will download and add the above mentioned library as a module.
  5. Now you should not have any kind of syntax error.
Shams Ul Azeem
  • 894
  • 9
  • 9
  • 4
    @ShamsUIAzeem after adding it gives me `The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar files deployed with this application` how to fix it – Kasun Siyambalapitiya May 18 '17 at 04:40
  • 10
    In my case adding the dependency `javax.servlet:jstl:1.2` **didn't work.** Adding the dependency `jstl:jstl:1.2` worked. – Arpan Srivastava Dec 03 '18 at 15:12
16

If you are using maven, add following code in pom.xml inside the <dependencies></dependencies> tag

<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>jstl</artifactId>
    <version>1.2</version>
</dependency>
Sineth Lakshitha
  • 619
  • 6
  • 14
4

If you are still getting errors after following the instructions provided by Shams UI Azeem, you may need to add the JSTL library to the WAR Exploded artifact. To do this:

  1. Go to Project Structure. Under Project Settings, select Artifacts. On the bottom of the menu box, there may be a message which mentions that the JSTL library used is not included in the WAR.

2a. Message visible. If the message is displayed, there should be a Fix button next to it. Click this Fix button. Select "add javax.servlet:jstl:1.2 to the artifact".

2b. Message not visible. If the message is not displayed, then look above to see if the javax.servet:jstl:1.2 (Project Library) is underneath the Available Elements column. If it is, right click it and select "Put into /WEB-INF/lib".

If you are working with Maven, the Fix message will not appear, though you will still need to do this.

Jack J
  • 1,514
  • 3
  • 20
  • 28
2

The problem is there because by default jstl jar is added for scope Compile Time Only We need to make it to get added for Runtime to do that.

  1. Click your project name and press F4 to bring up the module settings dialog or Right Click on Project name and find Open Module Settings.
  2. Go to the dependencies tab in the modules section.
  3. Find the javax.servlet:jstl:x.x, look at its scope, change it to Runtime.
  4. Also, you need to add jstl:jar to WEB-INF/lib folder.
Alexander Ivanchenko
  • 25,667
  • 5
  • 22
  • 46
1

As per Maven Repository, javax.servlet:jstl has moved to javax.servlet.jsp.jstl, however the later does not fix the URI resolution issue.

Adding the old javax.servlet:jstl dependency solves the issue.

Alex Ureche
  • 351
  • 2
  • 7
0

I finally got it to work using these:

<dependency>
    <groupId>javax.servlet.jsp.jstl</groupId>
    <artifactId>javax.servlet.jsp.jstl-api</artifactId>
    <version>1.2.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.glassfish.web/javax.servlet.jsp.jstl -->
<dependency>
    <groupId>org.glassfish.web</groupId>
    <artifactId>javax.servlet.jsp.jstl</artifactId>
    <version>1.2.1</version>
</dependency>
J.M. Janzen
  • 671
  • 1
  • 8
  • 19