Home » Enterprise Java » jstl » Use JSTL in JSP Page

About Ilias Tsagklis

Ilias Tsagklis
Ilias is a software developer turned online entrepreneur. He is co-founder and Executive Editor at Java Code Geeks.

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.

(No Ratings Yet)
Start the discussion Views Tweet it!

Do you want to know how to develop your skillset to become a Java Rockstar?

Subscribe to our newsletter to start Rocking right now!

To get you started we give you our best selling eBooks for FREE!

 

1. JPA Mini Book

2. JVM Troubleshooting Guide

3. JUnit Tutorial for Unit Testing

4. Java Annotations Tutorial

5. Java Interview Questions

6. Spring Interview Questions

7. Android UI Design

 

and many more ....

 

Receive Java & Developer job alerts in your Area

 

Leave a Reply

avatar
  Subscribe  
Notify of