JSP Entry 1. Sample Code of the jsp page when JSTL is not used
Example 1. Implement the Condition content through scriptlet
(Scriptlet: contains a valid program segment. Any text, HTML Tag, JSP element must be out of scriptlet)
- <% if (user.getRole() == "member")) { %>
- <p>Welcome, member!< /p>
- <% } else { %>
- <p>Welcome, guest!< /p>
- <% } %>
Fixing such problems usually requires a wealth of programming experience. Although JSP is usually developed and maintained by designers who are very proficient in page layout and graphic design, programmers are required to intervene when the script elements on the same page are faulty. In this situation, the Code responsibilities in a single file are shared to many people, making it a very troublesome task to develop, debug, and enhance such JSP pages. By packaging common functions into the standard set of custom tag libraries, JSTL allows JSP authors to reduce the need to compile script elements, or even skip them, and avoid related maintenance costs.
Introduction to JSTL 1.0
JSTL 1.0 was released in June 2002 and consists 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 to manage data by limiting the scope of variables, as well as performing page content iterations and conditional operations. It also provides tags for generating and operating URLs.
The format tag library defines operations for formatting data, especially numbers and dates. It also supports internationalization of JSP pages using localized resource bundle.
The xml library contains some tags that are used to manipulate data expressed in XML.
The SQL database defines the function used to query relational databases.
JSP entry 3. Expression Language EL)
The EL expression format is as follows: it is bounded by the dollar sign $) and the content is included in curly brackets.
Example 2: Describes the JSTL operation of the EL expression delimiters.
- < c:out value="${user.firstName}"/>
Example 3. Combine static text and multiple EL expressions to specify dynamic attribute values
- < c:out value="Hello ${user.firstName} ${user.lastName}"/>
JSP entry 4. Taglib pseudoinstructions
Example 4: Use the taglib pseudocommand for the EL version of The JSTL core library
- < %@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
JSP entry 5. Variable tag
Example 5 shows the operation syntax. The var attribute specifies the variable name, And the scope attribute indicates the scope in which the variable resides, the value Attribute specifies the value assigned to this variable. If the specified variable already exists, simply assign the specified value to it. If the variable does not exist, create a new variable that limits the scope and use this value to initialize the variable.
Example 5. <c: set> operation syntax
- < c:set var="name" scope="scope" value="${user.firstName}"/>
- How to connect to MySQL database in JSP
- Introduction to the Forward and sendRedirect methods of JSP
- Use JSP pages to generate PDF reports
- Step for customizing JSP labels
- Detailed test of JSP containers