Is the "c" prefix required in JSTL <c:forEach>?
I am studying JSTL part of JSP, I have a question about the <c:forEach>
loop ta开发者_如何学运维g. Is that c
prefix required? Does it indicate any specification?
Tag libraries in JSP are identified by tag library URIs. When you use a tag library in your JSP page, you import a tag library by its URI and bind it to some prefix:
<%@taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %>
After that you use the specified prefix to indentify tags from that library:
<c:foreach ...>
EDIT: These prefixes can be arbitrary, but there is a convention to use a value of the <short-name>
field in the tag library definition file (it's where c
for JSTL Core comes from)
You need some prefix, but it doesn't have to be c:
, that's just the convention. The prefix is specified when you declare the tag library at the top of the JSP, and it can be anything you like (within reason). The important part is the namespace URI (also specified in the JSP header), and that has to be a specific value (http://java.sun.com/jsp/jstl/core
in this case).
But you must have a prefix of some form, otherwise the JSP engine won't recognise it.
精彩评论