Mysterious Eclipse JSP Validation Errors
Solution 1
Based on the comments, I ended up turning off part of the JSP validation, which fixed this.
- Go to "Project->Properties->Validation".
- Click "Configure Workspace Settings...".
- 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.
Solution 2
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.
Solution 3
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.
Solution 4
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).
Solution 5
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?
worpet
Updated on July 09, 2022Comments
-
worpet almost 2 years
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:
- Incompatible operand types String and int line 1
- javax.servlet.jsp.JspException cannot be resolved to a type line 1
- javax.servlet.jsp.PageContext cannot be resolved to a type line 1
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.
-
dty over 13 yearsHonestly, I get these errors all the time from the Eclipse JSP editor - and stuff like underlining pieces of code which don't even syntactically go together - regardless of what JARs I add. Don't get me wrong, I'm a huge Eclipse fan, but the JSP editor is just useless.
-
Sancao about 13 yearsARGH! If the editor is misbehaving and the project's Build Path is correctly set up as Vivien describes, open a bug report.
-
Knubo over 12 yearsAdding a provided scope will probably also be smart as your container probably already has this installed.
-
Basil Musa over 12 yearsAdd a "<scope>provided</scope>" just before the </dependency> tag in the above maven dependency configuration (Just making Knubo's point clear)
-
Amit Patel over 12 years@MarkJosephDelRosario, this is also useful for different problem as well.
-
nwaltham about 12 yearsworks for me, needed a project --> clean after updating the pom
-
Sarah Vessels about 12 yearsJSP file is fine, I change some random bit of text (not even JSTL or JSP code), and suddenly I have little red squigglies everywhere, in random places (not even underlining the code they're complaining about). Then of course Rational Application Developer won't let me deploy my entire app to the server because it thinks there are errors. So stupid. Thanks for the fix.
-
Jason Stonebraker over 11 yearsI like this solution because it didn't require me to turn off jsp validation (throwing the baby out with the bath water IMO), and it didn't require me to make a change to the pom keeping the modification constrained to my local set up. Thanks!
-
JD Smith over 11 yearsI am glad this has worked for some folks, but even after cleaning after the pom update, re-running maven clean install, and refreshing the project, and even after un-checking all validators I still get the weird messages. I'm now going to try reinstalling everything from scratch using a newer version of STS based on Xander Plooy's answer below.
-
Sam YC about 10 yearswhy tomcat? what if I am not using tomcat?
-
el-teedee about 6 yearsJSP Content Validator found under Preferences > validation. (global validation settings, not JSP validation)