Reputation: 3893
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
Reputation: 3893
Based on the comments, I ended up turning off part of the JSP validation, which fixed this.
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
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
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
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
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
Reputation: 762
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
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
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
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
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
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
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
Reputation: 31
Solution for eclipse dependencies which should not be deployed is adding UserLibrary container, and include it in dependent projects.
You can do that for all *.jars which should not be deployed, but eclipse need it for validation purpose.
Upvotes: 2
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
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