jsp:include vs %@include for %@taglib functionality

25 Views Asked by At

I am using NetBeans 8.1 with the Spring framework and have stumbled on something I do not understand in relation too jsp:include and %@include and how it effects the availability or functionality of %@taglib entries.

I have this line at the top of my layout jsp that then includes my views.

 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

I am using this line to include my views to allow a layout to be used with more than on view.

  <jsp:include page="../views/${pa}.jsp"/>

In the view jsp I have the following code retrieving data from the database to create a drop down.

 <% List r = new com.mycompany.dbobjects.javaobject().main();%>
 <c:set var="n" value="<%=r%>"/>       
 <c:forEach items="${n}" var="item">
     <c:out value="${item.getID()}"/>
     <c:out value="${item.getName()}"/> 
 </c:forEach>

In order to get the data to appear using the jsp:include I have to add this line to the top of the view.

 <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

If I use a %@include and hard code the view name I do not need to put the %@taglib at the top of the view. Being new to JSP and Java I do not understand why the two includes change the placement of the %@taglib line.

0

There are 0 best solutions below