Introduction to the standard tag Library (JSTL) for getting started with JSP

Source: Internet
Author: User

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)

 
 
  1. <% if (user.getRole() == "member")) { %> 
  2.     <p>Welcome, member!< /p> 
  3. <% } else { %> 
  4.     <p>Welcome, guest!< /p> 
  5. <% } %>  

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.

 
 
  1. < c:out value="${user.firstName}"/> 

Example 3. Combine static text and multiple EL expressions to specify dynamic attribute values

 
 
  1. < 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

 
 
  1. < %@ 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

 
 
  1. < c:set var="name" scope="scope" value="${user.firstName}"/>
  1. How to connect to MySQL database in JSP
  2. Introduction to the Forward and sendRedirect methods of JSP
  3. Use JSP pages to generate PDF reports
  4. Step for customizing JSP labels
  5. Detailed test of JSP containers

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.