Iwan1993
Iwan1993

Reputation: 1779

JSP Fragment Tag causing error

i am trying to use fragment tags in my jsp files. The code in the tag file (base.tag) goes as follows

<%@tag description="Overall Page template" pageEncoding="UTF-8"%>

<%@attribute name="nav" fragment="true" %>
<%@attribute name="css" fragment="true" %>
<%@attribute name="js" fragment="true" %>
<!DOCTYPE html>
<html>
    <head>
    </head>
    <body>
        <jsp:invoke fragment="css" />
        <jsp:invoke fragment="nav" />
        <jsp:doBody/>
        <jsp:invoke fragment="js"/>
    </body>
</html>

My jsp looks like this:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:base>
    <jsp:attribute name="nav">
        <jsp:include page="nav.jsp" />
    </jsp:attribute>
    <jsp:body>
        <p>hi</p>
    </jsp:body>
    <jsp:attribute name="js">
        <p>hi</p>
    </jsp:attribute>
</t:base>

If i remove the fragment my code works fine - otherwise i get an "unterminated t:base" error. I am using tomcat 7.x if any other information required i will also post it here. But as i am new to tomcat/jsp/servlets i am pretty helpless.

Upvotes: 1

Views: 671

Answers (1)

Yo need to define all the attributes first:

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="UTF-8"%>
<%@ page import="java.util.ArrayList" %>
<%@ taglib prefix="t" tagdir="/WEB-INF/tags" %>
<t:base>

    <jsp:attribute name="js">
        <p>hi</p>
    </jsp:attribute>
    <jsp:attribute name="nav">
        <jsp:include page="nav.jsp" />
    </jsp:attribute>
    <jsp:body>
        <p>hi</p>
    </jsp:body>
</t:base>

Upvotes: 2

Related Questions