jstl
Use JSTL in JSP Page
In this example we shall show you how to use JSTL in a JSP page. The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications. The JSTL tags can be classified, according to their functions, into Core tags, Formatting tags, SQL tags and XML tags and they can be used when creating a JSP page. To include JSTL in a JSP page one should perform the following steps:
- Download the binary distribution from Apache Standard Taglib and unpack the compressed file. To use the Standard Taglib from its Jakarta Taglibs distribution, simply copy the JAR files in the distribution’s ‘lib’ directory to your application’s webapps\ROOT\WEB-INF\lib directory.
- Create a jsp page that contains the
<%code fragment%>
scriptlet. It can contain any number of JAVA language statements, variable or method declarations, or expressions that are valid in the page scripting language. - Include JSTL Core library in your JSP page, using the
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
syntax,
as described in the code snippet below.
SimpleJSTL.jsp
<%@ page language="java" contentType="text/html;charset=UTF-8" %> <%@ taglib uri="/WEB-INF/tld/c-rt.tld" prefix="c-rt" %> <html> <head> <title>Java Code Geeks Snippets - Simple JSTL in JSP Page</title> </head> <body> <c-rt:if test='<%= request.getParameter("myparam") != null %>'> <%= request.getParameter("myparam") %> </c-rt:if> </body>
URL:
http://localhost:8080/jcgsnippets/SimpleJSTL.jsp?myparam=myvalue
Output:
myvalue
This was an example of how to use JSTL in a JSP page.