views:

155

answers:

3

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.

A: 

As far as I can make out, Eclipse's JSP editor is a total bag of bolts. Not that this is a useful answer, of course! :-)

dty
A: 

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.

Vivien Barousse
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.
dty
+1  A: 

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

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.

worpet