7

I've got a JSP and I'm going to start using the JSTL taglib. So I need to declare it and I do it by the row

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

But where do I put this code? At the top of the file, before everything, or after imports? Does it matter?

BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
Niklas Rosencrantz
  • 25,640
  • 75
  • 229
  • 424

3 Answers3

6

Usually right at the top of the file. If you start using multiple taglibs you could also move it to a separate include file to safe typing. For example

/WEB-INF/jspf/taglibs.jspf

<%@ page contentType="text/html;charset=utf8"%>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c"%>

/WEB-INF/jsp/index.jsp

<%@ include file="/WEB-INF/jspf/taglibs.jspf" %>
Jörn Horstmann
  • 33,639
  • 11
  • 75
  • 118
2

I usually put it before anything, even before the <%@ page %>.

Just a little trick to have a cleaner HTML code generated, put them like this:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"
%><%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"
%><%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"
%><html>
...
</html>
sp00m
  • 47,968
  • 31
  • 142
  • 252
2

You put the taglib declaration right at the top of the file before everything else.

Deco
  • 3,261
  • 17
  • 25