I am using Tiles within my web-application. I have a standard-layout (standard.jsp) within the tiles are used. On top of the standard.jsp are a lot of includes, concerning tag-libraries and such.

Let's do a simplified example.

standard.jsp:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/jsp/includes/include.jsp" %>

<html>

<head>
    <tiles:insertAttribute name="head" flush="false"/>
</head>

<body>
    <tiles:insertAttribute name="body" flush="false"/>
</body>    

</html>

body.jsp:

<div id="body-div">
    <p>Hello, <c:out value="${forname}" />!</p>
</div>

This prints:

Hello, !

In the tiles I would like to use the tags, but it's not working. It only works, if I add the includes to the tile-jsp.

body.jsp with includes:

<%@ include file="/WEB-INF/jsp/includes/include.jsp" %>

<div id="body-div">
    <p>Hello, <c:out value="${forname}" />!</p>
</div>

This prints:

Hello, John!

Is there a better way to do this or do I have to add all includes to every jsp used?

Accepted Answer

You don't need ALL includes to be present in each of your tiles, but each used tag-library in a tile must specifically be included in the using tile.

eg : In your example, each tile using the C JSTL library should at least have the <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> include

Written by WiseTechi
This page was build to provide you fast access to the question and the direct accepted answer.
The content is written by members of the stackoverflow.com community.
It is licensed under cc-wiki