Rather than writing Java code directly in your JSP file, you can store common functions in a tag library and implement the functions using simple tags. This practice makes the JSP file more readable and isolates the JSP file from any underlying implementation changes.
For example, here is the code you would add to your JSP file to use the JSP Standard Tag Library conditional tags. The prefix is an arbitrary string that identifies the tag library associated with a particular tag. Within a JSP file, all taglib prefixes must be unique. Since the prefix is arbitrary, you do not need to use the same one each time you reference a particular taglib. However, it is good practice to use the same prefix for a particular taglib within a web module.
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core" %>
![]() |
The web module's deployment descriptor file, web.xml,
is automatically updated to include the new tag library element. The tag
library element chooses a default URI based on the file name of the JAR
file. This URI is the name that should be used in the <%taglib%>
directive in your JSP file. Adding a tag library .jar file also causes it to be mounted in the Filesystems window, if its development directory is not already mounted. |
See Also | |
---|---|
Custom Tag Libraries Using Custom Tags in JSP Files Creating Custom Tag Libraries |