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.
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> <% } %>
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!