Mysterious Eclipse JSP Validation Errors

56,416

Solution 1

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.

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?

Share:
56,416
worpet
Author by

worpet

Updated on July 09, 2022

Comments

  • worpet
    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
    dty over 13 years
    Honestly, 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
    Sancao about 13 years
    ARGH! If the editor is misbehaving and the project's Build Path is correctly set up as Vivien describes, open a bug report.
  • Knubo
    Knubo over 12 years
    Adding a provided scope will probably also be smart as your container probably already has this installed.
  • Basil Musa
    Basil Musa over 12 years
    Add a "<scope>provided</scope>" just before the </dependency> tag in the above maven dependency configuration (Just making Knubo's point clear)
  • Amit Patel
    Amit Patel over 12 years
    @MarkJosephDelRosario, this is also useful for different problem as well.
  • nwaltham
    nwaltham about 12 years
    works for me, needed a project --> clean after updating the pom
  • Sarah Vessels
    Sarah Vessels about 12 years
    JSP 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
    Jason Stonebraker over 11 years
    I 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
    JD Smith over 11 years
    I 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
    Sam YC about 10 years
    why tomcat? what if I am not using tomcat?
  • el-teedee
    el-teedee about 6 years
    JSP Content Validator found under Preferences > validation. (global validation settings, not JSP validation)