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?
This taglib contains tags used to create struts input forms, as well as other tags generally useful in the creation of HTML-based user interfaces.
The taglib directive declares that your JSP page uses a set of custom tags, identifies the location of the library, and provides means for identifying the custom tags in your JSP page.
The taglib Directive Specify a shortcut URI, as defined in a web. xml file (see "Use of web. xml for Tag Libraries" above). Fully specify the tag library description (TLD) file name and location.
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" %>
You put the taglib declaration right at the top of the file before everything else.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With