worpet
worpet

Reputation: 3893

Mysterious Eclipse JSP Validation Errors

Eclipse (Helios) occasionally marks valid looking JSP content as having errors. It seems like it often breaks when I use the <c:if> tag. For example, in a JSP with just this content:

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

<c:if test="${1 == 1}">
something
</c:if>

</body>
</html>

The following errors show in the "Problems" tab after I compile:

The code runs fine. Does the validation for JSPs have issues, am I missing something obvious, or does this indicate something isn't set up correctly.

Upvotes: 49

Views: 57677

Answers (16)

worpet
worpet

Reputation: 3893

Based on the comments, I ended up turning off part of the JSP validation, which fixed this.

  1. Go to "Project->Properties->Validation".
  2. Click "Configure Workspace Settings...".
  3. Unselect options for JSP Syntax Validator (both manual and build).

I was hoping I was missing something and there was a way to fix this, but I have to concede that the JSP validation is junk.

Upvotes: 38

user1668969
user1668969

Reputation: 93

For me, while I was typing the line manually, I got an error until I closed the tag, but the error never went away. I found a line of code that was similar, and I deleted the offending code, copy and pasted the the good code, and then made changes inside the tag as needed. No more errors!!! Not an ideal solution, but it worked for me.

Upvotes: 1

ChrisP
ChrisP

Reputation: 1

As many of you have mentioned, the issues is around the build path and missing libraries. I found a very simple fix to this build path issue. Here is the solution: Under 'Java Build Path' in eclipse, go to the 'Order and Export' tab, and make sure that the 'Apache Tomcat v7.0' libraries (or whichever version of Tomcat you installed with eclipse) are checked. This instantly fixes the problem. No hassle with anything else. :-)

There is no need to turn off any validation in that case either.

Upvotes: 0

Jafar Ali
Jafar Ali

Reputation: 1114

A much easier way is to

select the project -> Properties -> Java Build Path -> Libraries Tab

Select add Libraries. From there select Server Runtime. It will list all the server runtimes you have configured. From there Select the server runtime you have assosiated your project with.

This will rebuild and revalidate the projece and all this ghost errors will be removed.

Hope this helps.

Upvotes: 1

Mick&#228;el A.
Mick&#228;el A.

Reputation: 9377

I had the same problem, but both jsp-api.jar and servlet-api.jar were already in build path. Disabling JSP Syntax Validator didn't help as well.

Instead, I had to disable JSP Content Validator, leaving the syntax validator enabled. I still have underlined code in my JSP but no red cross indicating compiling error and that's the point :)

Upvotes: 1

Well, I found how to solve this error. Add this to your Maven dependency(pom.xml):

<!-- dependency to fix JSPServletException -->
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>jsp-api</artifactId>
        <version>6.0.32</version>
        <scope>provided</scope>               
    </dependency>

Do comment if you find it useful, as much as it helped me.

Upvotes: 47

Xander Plooy
Xander Plooy

Reputation: 31

This is an old question but thought I might mention I get this too in Juno on Mac OS X—specifically most often after i change a file externally and then refresh the project in Eclipse. Underlines in all sorts of odd places, even halfway through words in JSP comments.

Could (likely?!) be related to bug 376926 which apparently got fixed a bit over a week ago?

Upvotes: 3

jackxie
jackxie

Reputation: 1

Adding jsp-api.jar into your build classpath would fix it. jsp-api.jar is under common\lib for tomcat 5.x

Upvotes: 0

scarba05
scarba05

Reputation: 3001

For Tomcat 7.0.x you need the following in your pom

<properties>
    <org.apache.tomcat.version>7.0.28</org.apache.tomcat.version>
</properties>

<dependencies>
    <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-jsp-api</artifactId>
        <version>${org.apache.tomcat.version}</version>
        <scope>provided</scope>
    </dependency>
</dependencies>

Upvotes: 2

Christiaan
Christiaan

Reputation: 2725

I had the same problem and eventually got it to work by switching (with Maven) to version 2.3 of the servlet-api:

<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.3</version>
    <scope>provided</scope>
</dependency>

Apparently 2.4 and higher don't have javax.servlet.jsp build in anymore. You might be able to find that library in another package if you still want to use 2.4 or higher.

Upvotes: 1

rjcorujo
rjcorujo

Reputation: 221

I had the same problem, the problem is the jsp-api library, you can add the dependency to your pom (as explained in other answers) or you can also add the target run-time and eclipse will automatically add that library to your class-path:

Project -> Properties -> Targeted Runtimes 

And select your server.

Upvotes: 21

deng hui
deng hui

Reputation: 1

I also see the same problem during I shift to Maven (with m2e), get error like "javax.servlet.http cannot be resolved" and some Spring tags undefined warning. finally I find it's because java version (v1.6) in my build configuration is not same as in facets configuration (v1.7). after change v1.7 to v1.6 the problem disappear.

Upvotes: 0

Vishal
Vishal

Reputation: 11

You need to include jap-api.jar in your classpath.

Upvotes: 1

kmajetic
kmajetic

Reputation: 31

Solution for eclipse dependencies which should not be deployed is adding UserLibrary container, and include it in dependent projects.

  1. Create dir e.g /home/user*/eclipse-deps/ and copy jsp-api.jar from */tomcat/lib dir
  2. In the Eclipse go to project properties->build path, and create new "UserLibrary" eg. IdeDeps.
  3. Include /home/user/eclipse-deps/ in IdeDeps library, and include user library in all projects which are dependent on jsp-api.jar (in classpath: < classpathentry kind="con" path="org.eclipse.jdt.USER_LIBRARY/IdeDeps"/ >)

You can do that for all *.jars which should not be deployed, but eclipse need it for validation purpose.

Upvotes: 2

Paranoja
Paranoja

Reputation: 51

In order to fix:
- javax.servlet.jsp.* needs jsp-api.jar
- javax.servlet.http.* needs servlet-api.jar

You need to add these libraries to Java Build path in project setup. These libraries can be found in tomcat/lib directory (for Tomcat 6.0).

Upvotes: 5

Vivien Barousse
Vivien Barousse

Reputation: 20875

Try to check your project classpath. It looks like you don't have the JSP library in your project (hence the "JspException cannot be resolved"), or that your library version isn't the same as the JSP compiler version.

The library is included by default in the application server on which you deploy your app, so the code runs perfectly when deployed. However, if the Eclipse internal compiler is missing a library (or have an incorrect version), the Eclipse editor shows you error that doesn't exists in app server.

Upvotes: 1

Related Questions