Home Java javaTutorial what is jstl

what is jstl

May 15, 2019 am 10:42 AM

JSTL's full name is JavaServer Pages Standard Tag Library, which means "JSP Standard Tag Library" in Chinese. It is an open source JSP tag library that is constantly improving. Developers can use these tags to replace Java code on JSP pages, thereby improving the readability of the program and reducing the difficulty of program maintenance.

what is jstl

JSTL (Java server pages standardized tag library, JSP standard tag library) is a standard specification developed by JCP (Java community Proces). It mainly provides Gives Java Web developers a standard, universal tag library maintained by Apache's Jakarta team. Developers can use these tags to replace Java code on JSP pages, thereby improving the readability of the program and reducing the difficulty of program maintenance.

JSTL can only run on containers that support JSP1.2 and Servlet2.3 specifications, such as tomcat 4.x. It is also supported as a standard in JSP 2.0.

Recommended course: Java Tutorial.

JSTL 1.0 was released in June 2002 and consisted of four custom tag libraries (core, format, xml, and sql) and a pair of universal tag library validators (ScriptFreeTLV and PermittedTaglibsTLV). The core tag library provides custom operations, manages data through scoped variables, and performs iteration and conditional operations on page content. It also provides markup for generating and manipulating URLs. As the name suggests, the format tag library defines operations for formatting data, specifically numbers and dates. It also supports internationalization of JSP pages using localized resource bundles. The xml library contains tags for manipulating data represented through XML, while the sql library defines operations for querying relational databases.

If you want to use JSTL, you must put the jstl.jar and standard.jar files in the classpath. If you also need to use XML processing and Database access (SQL) tags, you must also put the relevant JAR files in In the classpath, these JAR files all exist in the downloaded zip file.

The elegant programming experience brought by Jstl is well known to everyone. Today, when the Java community is booming, there is no need to consider many issues when using jstl. We can easily build a jstl web project using a java integrated development environment such as myeclipse. Even with a powerful tool like myeclipse that helps us quickly develop web projects, there is some knowledge that we must understand - that is, the dependency between jstl and servlet versions, and jsp versions.

Detailed introduction

JSP Standard Tag Library (JSTL) is a set of customized tag libraries that implement common common functions in Web applications. These Functionality includes iteration and conditional judgment, data management formatting, XML operations, and database access. In the first article in a new series on developerWorks, software engineer Mark Kolb shows you how to use JSTL tags to avoid scripting elements in JSP pages. You'll also learn how to simplify software maintenance by removing source code from the presentation layer. Finally, you'll learn about JSTL's simplified expression language, which allows you to specify dynamic property values ​​for JSTL operations without having to use a full-featured programming language.

JavaServer Pages (JSP) is the standard presentation layer technology for the J2EE platform. JSP technology provides scripting elements and operations for performing calculations that are used to dynamically generate page content. Scripting elements allow you to include program source code in a JSP page, which can be executed when the page is rendered in response to a user request. Actions encapsulate computational operations into tags much like HTML or XML tags that are often included in the template text of a JSP page. The JSP specification defines only a few operations as standard, but starting with JSP 1.1, developers have been able to create their own operations in the form of custom tag libraries.

The JSP Standard Tag Library (JSTL) is a set of JSP 1.2 custom tag libraries that implement a number of basic functions commonly used by server-side Java applications. By providing standard implementations for typical presentation layer tasks such as data formatting and iteration or conditional content, JSTL allows JSP authors to focus on application-specific development needs rather than "reinventing the wheel" for these common operations.

Of course, you can use JSP scripting elements (scriptlets, expressions, and declarations) to accomplish such tasks.

For example, you can implement conditional content using three scriptlets, highlighted in Listing 1. However, because scripting elements rely on embedding program source code (usually Java code) in the page, the complexity of software maintenance tasks for JSP pages that use these scripting elements increases significantly. For example, the scriptlet example in Listing 1 relies strictly on correct matching of curly braces. Nesting other scriptlets within conditional content can wreak havoc if a syntax error is inadvertently introduced, and it can be difficult to make the resulting error message meaningful when the JSP container compiles the page.

List 1. Implement conditional content through scriptlet

<% if (user.getRole() == "member")) { %>
<p>Welcome, member!</p>
<% } else { %>
<p>Welcome, guest!</p>
<% } %>
Copy after login

Correcting such problems usually requires considerable programming experience. Although JSPs are typically developed and maintained by designers who are well versed in page layout and graphic design, problems with scripting elements within the same page require programmer intervention. This situation spreads the responsibility for the code in a single file among multiple people, making developing, debugging, and enhancing such JSP pages a cumbersome task. By wrapping commonly used functionality into a standard collection of custom tag libraries, JSTL enables JSP authors to reduce the need for scripting elements or even eliminate them and avoid the associated maintenance costs

Example It is very simple to display the backend data into the page:

Your username is:

Display the user's username. If it is empty, the guest will be displayed.

Specify from Get the value of username in session and display it;

Display the value of username. The default is to take it from request(page). If request If there is no object named username, it is taken from the session. If there is no object named username in the session, it is taken from the application (servletContext). If no value is obtained, it will not be displayed.

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

Statement of this Website
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

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

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Is the company's security software causing the application to fail to run? How to troubleshoot and solve it? Apr 19, 2025 pm 04:51 PM

Troubleshooting and solutions to the company's security software that causes some applications to not function properly. Many companies will deploy security software in order to ensure internal network security. ...

How to simplify field mapping issues in system docking using MapStruct? How to simplify field mapping issues in system docking using MapStruct? Apr 19, 2025 pm 06:21 PM

Field mapping processing in system docking often encounters a difficult problem when performing system docking: how to effectively map the interface fields of system A...

How to elegantly obtain entity class variable names to build database query conditions? How to elegantly obtain entity class variable names to build database query conditions? Apr 19, 2025 pm 11:42 PM

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

How do I convert names to numbers to implement sorting and maintain consistency in groups? How do I convert names to numbers to implement sorting and maintain consistency in groups? Apr 19, 2025 pm 11:30 PM

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? How does IntelliJ IDEA identify the port number of a Spring Boot project without outputting a log? Apr 19, 2025 pm 11:45 PM

Start Spring using IntelliJIDEAUltimate version...

How to safely convert Java objects to arrays? How to safely convert Java objects to arrays? Apr 19, 2025 pm 11:33 PM

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? E-commerce platform SKU and SPU database design: How to take into account both user-defined attributes and attributeless products? Apr 19, 2025 pm 11:27 PM

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? How to elegantly get entity class variable name building query conditions when using TKMyBatis for database query? Apr 19, 2025 pm 09:51 PM

When using TKMyBatis for database queries, how to gracefully get entity class variable names to build query conditions is a common problem. This article will pin...

See all articles