Compiling .jsp Fragments in Eclipse

The ability to generate HTML or .JSP fragments that you can include on multiple pages of your site enables you to re-use code and increase maintainability.

However, if you need to include functions (or methods) and fields (or variables) in one fragment that is included on a page and then utilize them in another fragment included in the same page Eclipse will give you compile errors because it concludes that your references are out of scope.

The solution is quite simple:? Instead of naming the fragments .jsp, use some other extension (.jnc, .jinc, etc) for the fragements that contain references to variables or functions that are included on the parent page and use the <%@ include %> directive as this includes the content of the fragment at compile time.

Leave a Reply