search

JSTL abbreviated as Java Standard Tag Library, which is a further extension for JSP (Java Server Pages). JSTL reduced the lines of code for the developer. This JSTL supports for structural tasks, a common task like conditional and iteration. These tags used for changing I18N (Internationalization) tags, SQL tags, XML documents, etc. This also provides a framework for attaching the already existing custom tags within the Java Standard Tag Library.

Start Your Free Software Development Course

Web development, programming languages, Software testing & others

Advantages of JSTL:

  • Fast Development.
  • Code Reusability.
  • No need to use a scriptlet tag.

How does JSTL Work in Java?

JSTL works based on the type of tag we have used in our application. It consists of around 5 types of tags. They are

  1. Core tags
  2. Function tags
  3. Formatting tags
  4. XML tags
  5. SQL tags

JSTL tags Description:

Tag Type Description URI to include prefix
Core tags The JSTL core tag provides flow control, variable support, URL management etc. http://java.sun.com/jsp/jstl/core c
Function tags This function tag is used for String manipulation and
String length
http://java.sun.com/jsp/jstl/
functions
fn
Formatting tags This formatting tag is used for number, date and message formatting http://java.sun.com/jsp/jstl/fmt fmt
XML tags This XML tag is used for transformation and flow control etc. http://java.sun.com/jsp/jstl/xml x
SQL tags This SQL tag is used to provide support for SQL support.  http://java.sun.com/jsp/jstl/sql sql
Tag Type
Description URI to include prefix
Core tags The JSTL core tag provides flow control, variable support, URL management etc. http://java.sun.com/jsp/jstl/core c
Function tags This function tag is used for String manipulation and
String length
http://java.sun.com/jsp/jstl/
functions
fn
Formatting tags This formatting tag is used for number, date and message formatting http://java.sun.com/jsp/jstl/fmt fmt
XML tags This XML tag is used for transformation and flow control etc. http://java.sun.com/jsp/jstl/xml x
SQL tags This SQL tag is used to provide support for SQL support.  http://java.sun.com/jsp/jstl/sql sql

Each JSTL tag have again consisting of different sub tags. Now time being, we will some of the examples of core tags and function tags.

Note: Make use of these functionalities; we must use the jstl.1.X.jar file. X indicates the version.

Examples

Following are the examples are given below:

Project Structure in eclipse:

JSTL In Java

Example #1 – Core tag c:out

Code: NewFile.jsp



<title>JSTL Tags</title>


<!--THis c:out tag is used for displaying output-->
<out value="${'Hello Amardeep, Wel come to EDUCBA online courses.'}"></out>

Output:

JSTL In Java

Example #2 – Core tag set and c:if tags

Code: SetCIf.jsp



<title>JSTL Tags</title>


<set var="money" scope="session" value="${5000*5}"></set>
<if test="${money > 8000}">
<p>My Salary is: <out value="${money}"></out></p>
<p>
</p></if>

Output:

JSTL In Java

Example #3 – Core tag with c:choose tag

Code: CChoose.jsp



<title>JSTL Tags</title>


<set var="money" scope="session" value="${5000*5}"></set>
<p>Your income is : <out value="${money}"></out></p>
<choose>
<when test="${money <= 1000}">
You are paid with good salary.
</when>
<when test="${money > 10000}">
You are paid with really good salary.
</when>
<otherwise>
You are paid with low salary .
</otherwise>
</choose>

Output:

JSTL In Java

Example #4 – Core tag with c:when tag

Code: CWhen.jsp



<title>JSTL Tags</title>


<set value="214" var="digit"></set>
<choose>
<when test="${digit%2==0}">
<out value="${digit} is EVEN digit"></out>
</when>
<otherwise>
<out value="${digit} is ODD digit"></out>
</otherwise>
</choose>

Output:

JSTL In Java

Example #5 – Core tag with c:foreach tag

Code: CForeach.jsp



<title>JSTL Tags</title>


<foreach var="iterator" begin="100" end="110">
Count: <out value="${iterator}"></out>
<p>
</p></foreach>

Output:

JSTL In Java

Example #6 – Core tag with c:forTokens tag

Code: CForTokens.jsp



<title>JSTL Tags</title>


<fortokens items="My-Name-is-Nathi-Paramesh" delims="-" var="del">
Word: <out value="${del}"></out>
<p>
</p></fortokens>

Output:

 JSTL In Java

Example # 7 – Core tag with c:redirect tag

Code: CRedirect.jsp



<title>JSTL Tags</title>


<set var="urlName" value="2" scope="request"></set>
<if test="${urlName<1}">
<redirect url="http:/educba.com"></redirect>
</if>
<!-- Page directly redirect to gmail because value is greater than 1 -->
<if test="${urlName>1}">
<redirect url="http://gmail.com"></redirect>
</if>

Output:

 JSTL In Java

Example #8 – Function tag with c:contains tag

Code: FunctionContains.jsp




<title>JSTL Tags</title>


<set var="StringType" value="We are learning online course from EDUCBA platform"></set>
<if test="${fn:contains(StringType, 'EDUCBA')}">
<h1 style="color: green">Yes Given String found in the value
</h1>
<p style="color:blue;border: 1px solid red;font-size:20px">JSTL abbreviated as Java Standard Tag Library. Which is
further extension for JSP (Java Server Pages). JSTL reduced the lines
of code for developer. This JSTL supports for structural tasks,
common task like conditional and iteration. This tags used for
changing I18N (Internationalization) tags, SQL tags, XML documents
etc. This JSTL also provides a framework for attaching the already
existing custom tags within the Java Standard Tag Library.</p>
</if>
<if test="${fn:contains(StringType, 'courses')}">
<p>No Given String is not found in the value
</p>
<p>
</p></if>

Output:

 JSTL In Java

Example # 9 – Function tag with c:endsWith tag

Code: CEndsWith.jsp




<title>JSTL Tags</title>


<set var="StringType" value="We are learning online course from EDUCBA platform"></set>
<if test="${fn:endsWith(StringType, 'platform')}">
<h1 id="Yes-String-ends-with-platfrom">Yes String ends with platfrom.</h1>
<p style="color: fuchsia; border: 1px solid red; font-size: 20px">JSTL
abbreviated as Java Standard Tag Library. Which is further extension
for JSP (Java Server Pages). JSTL reduced the lines of code for
developer. This JSTL supports for structural tasks, common task like
conditional and iteration. This tags used for changing I18N
(Internationalization) tags, SQL tags, XML documents etc. This JSTL
also provides a framework for attaching the already existing custom
tags within the Java Standard Tag Library.</p>
</if>
<if test="${fn:endsWith(String, 'are')}">
<p>String ends with are.
</p>
<p>
</p></if>

Output:

JSTL In Java

The above is the detailed content of JSTL In Java. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
How to get Java entity class attribute names elegantly to avoid hard-coded in MyBatis queries?How to get Java entity class attribute names elegantly to avoid hard-coded in MyBatis queries?Apr 19, 2025 pm 08:27 PM

When using MyBatis-Plus or tk.mybatis...

How to efficiently query personnel data in MySql and ElasticSearch through natural language processing?How to efficiently query personnel data in MySql and ElasticSearch through natural language processing?Apr 19, 2025 pm 08:24 PM

How to query personnel data through natural language processing? In modern data processing, how to efficiently query personnel data is a common and important requirement. ...

How to parse next-auth generated JWT token in Java and get information in it?How to parse next-auth generated JWT token in Java and get information in it?Apr 19, 2025 pm 08:21 PM

In processing next-auth generated JWT...

Why can't JavaScript directly obtain hardware information on the user's computer?Why can't JavaScript directly obtain hardware information on the user's computer?Apr 19, 2025 pm 08:15 PM

Discussion on the reasons why JavaScript cannot obtain user computer hardware information In daily programming, many developers will be curious about why JavaScript cannot be directly obtained...

Circular dependencies appear in the RuoYi framework. How to troubleshoot and solve the problem of dynamicDataSource Bean?Circular dependencies appear in the RuoYi framework. How to troubleshoot and solve the problem of dynamicDataSource Bean?Apr 19, 2025 pm 08:12 PM

RuoYi framework circular dependency problem troubleshooting and solving the problem of circular dependency when using RuoYi framework for development, we often encounter circular dependency problems, which often leads to the program...

When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure?When building a microservice architecture using Spring Cloud Alibaba, do you have to manage each module in a parent-child engineering structure?Apr 19, 2025 pm 08:09 PM

About SpringCloudAlibaba microservices modular development using SpringCloud...

Treatment of x² in curve integral: Why can the standard answer be ignored (1/3) x³?Treatment of x² in curve integral: Why can the standard answer be ignored (1/3) x³?Apr 19, 2025 pm 08:06 PM

Questions about a curve integral This article will answer a curve integral question. The questioner had a question about the standard answer to a sample question...

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version

Dreamweaver Mac version

Dreamweaver Mac version

Visual web development tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)