Mason
Mason

Reputation: 8846

How do I get Eclipse to syntax check inside <%@ include %> directives in JSP?

When I'm using <%@ include %> directives in JSP, is there any way to have Eclipse syntax check my included files (or what is best practice for this). What I mean is that if I include files that have variables declared in the parent, I get a bunch of errors about undeclared variables (makes sense).

So how do people get around this?

Upvotes: 6

Views: 3154

Answers (4)

nitind
nitind

Reputation: 20003

The contents of your fragment will be validated as part of validating the main file, meaning any errors found will be reported back to the include directive in the main file. Your fragment may be correct or invalid for different reasons depending on which file is including it, assuming any files include it at all.

Upvotes: 0

BalusC
BalusC

Reputation: 1108802

Disable JSP validation in Eclipse (it has always been a failure), or, better, just don't use scriptlets. It's considered bad practice. Keep Java code in real Java classes and use taglibs/EL in JSP all the way.

Upvotes: 2

justkt
justkt

Reputation: 14766

The best practice is to encapsulate all Java code as tags, and then use the tags in your JSP. As a bonus when you do this you'll be writing your java in .java files, whose syntax Eclipse will check for you. You can find more information about tags from Sun

Upvotes: 2

kg.
kg.

Reputation: 631

Are you sure you are using

<%@ include ... %>

and not

<jsp:include ... >? 

I would like to clarify that this is the scenario you are talking about:

includeMe.jsp:

<%@ page language="java" %>
<%
boolean testBoolean = true;
%>

App.jsp:

<%@ page language="java" %>
<%@include file="/WEB-INF/includeMe.jsp"%>
<%
testBoolean = false;
%>

And you are getting the undeclared variable error on testBoolean in App.jsp file? If this is the case, I'm not sure what is wrong, because I can't reproduce this issue in Eclipse 3.5 (with WTP installed).

This might help as well: Variables in jsp pages with "included" pages

Upvotes: 0

Related Questions