The subtle relationship between Java learning--jstl tags and el expressions

Source: Internet
Author: User

The original summed up too good, can't help recording, forwarding.

Original address: http://blog.csdn.net/u010168160/article/details/49182867

Directory (?) [-]

    1. One-El expression
      1. El Related Concepts
      2. El Basic Format
      3. El syntax composition-identifier
        1. PS When using El the default will be in a certain order pagecontextrequestsessionapplication search four scopes to display the first found variable values
      4. Turn El expressions on and off
    2. Two JSTL Tag Library
      1. Related concepts
      2. Jstl Tag Library Categories
      3. Advantages of Jstl
      4. Why do you use Jstl
      5. How to use
    3. Summarize

I'm glad to share some of the new knowledge we have just learned with you today. We often embed some Java code in the JSP in the Java development process, for example <%=request.getParameter("id")%> , in the people who understand the Java code, this is very simple, but for the artist or the front desk does not understand the Java code of people, this is a headache. So today we're going to solve this problem.

I. El expression 1, El related concepts

Jstl is generally used in conjunction with El Expressions to implement Java code snippets that do not appear in JSPs. So let's learn the El expression first.
EL (expression Language) expression language : Used to calculate and output the values of Java objects stored at the flag location (page, request, session, application) and then perform simple operations on them El is part of the JSP2.0 specification and can be used directly in JSP2.0 Web pages as long as the container supports servlet2.4/jsp2.0. Usually works with the JSTL tag to represent complex behavior with simple and convenient symbols.

2. El Basic Format

El expression format: delimited with dollar sign ($), content included in curly braces ({});

例如: 点号记法:${BeanName.beanProperty}数组记法:${BeanName[“beanProperty”]}
    • 1
    • 2
    • 3
    • 1
    • 2
    • 3

In addition, you can combine multiple expressions with static text to construct dynamic property values through string literals;

例如:Hello {loginInfoBean.suser} ${loginInfoBean.spwd}
    • 1
    • 1
3. El syntax composition-identifier
    • (1) El hidden Objects
      Common

PS: When using El, the default is to search for four scopes in a certain order (PageContext, request, session, application), showing the values of the variables that were first found.
    • (2) El accessor

An element that an accessor uses to retrieve an attribute or collection of an object. Accessors: Get related data through the "[]" or "." Symbols

例://获取输出bean中的suser属性值;${userBean.suser}  或  ${userBean[“suser”]}//获取map中key为id对应的值;${mcType[“id”]} 
    • 1
    • 2
    • 3
    • 4
    • 5
    • 1
    • 2
    • 3
    • 4
    • 5
    • (3) El operator

4. Turn on and off El expressions
    • (1) Opening method

After servlet2.4, the default method is False, which can be written or

<%@ page isELIgnored="false" %>
    • 1
    • 1
    • (2) Closing method
<%@ page isELIgnored="true" %>
    • 1
    • 1

There is also a method for bulk disabling El, which can be configured in bulk disable El,web.xml in Web-inf/web.xml using jsp-property-group tags.

<?xml version= "1.0" encoding= "UTF-8"?><Web-appxmlns="Http://java.sun.com/xml/ns/j2ee"Xmlns:xsi="Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version= "2.4" > < jsp-config> <jsp-property-group > <url-pattern>*.jsp</url-pattern> <el-ignored>true</el-ignored> </ jsp-property-group> </jsp-config ></WEB-APP>       
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
Second, jstl Tag library 1, Related concepts

JSTL (JSP standard tag LIBRARY,JSP standards Tag library) is an ever-improving open source JSP tag library that is maintained by Apache's Jakarta team. The JSTL1.0 consists of four custom tag libraries (core, format, XML, and SQL) and a pair of common tag library validators.
If you want to use JSTL, you must refer to the Jstl.jar and Standard.jar two packages.

2, JSTL Tag Library classification

The core tag library provides custom actions to manage data by limiting the scope of variables, as well as performing iterations and conditional actions on page content. It also provides tags for generating and manipulating URLs.
The Format tag library defines the operations that are used to format data, especially numbers and dates. It also supports the internationalization of JSP pages using localized resource bundles.
The XML library contains tags that manipulate the data represented by XML, and the SQL Library defines the operations that are used to query the relational database.
Two JSTL tag library validators allow developers to enforce coding standards in their JSP applications.

3, the advantages of JSTL

4, why to use Jstl

Our JSPs are very handy for developing information presentation pages, and you can embed Java code (scriptlet, expressions, and declarations) code to implement related logical controls. Look at the procedure below. However, this can lead to the following problems:

jsp维护难度增加;
    • 1
    • 1
出错提示不明确,不容易调试;
    • 1
    • 1
分工不明确;(即jsp开发者是美工,也是程序员);
    • 1
    • 1
最终增加程序的开发成本;
    • 1
    • 1

To solve the above problems, you can use the custom tag library, which allows JSP developers to reduce the need for scripting elements, or even jstl them, to avoid the associated maintenance costs. Make the division of labor more clear. Jstl is generally used in conjunction with EL, so look at El first.

5. How to use

Need to introduce a tag library

<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" Prefix= "C" %><%@ taglib uri=" http://java.sun.com /jsp/jstl/fmt "Prefix=" FMT "%>< %@ taglib uri= "Http://java.sun.com/jsp/jstl/xml" prefix=< Span class= "hljs-string" > "x" %><%@ taglib Uri= "Http://java.sun.com/jsp/jstl/sql" Prefix= "SQL" %><%@ taglib uri= "http:/ /java.sun.com/jsp/jstl/functions "Prefix=" FN "%>   
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

detailed steps See next blog:Java learning--jstl Tag Library Daquan

Summarize:

By learning from Jstl and El, we can use simple tags at the front desk instead of the Java code we need to write, so we have a clearer division of labor. Our world is the need to simplify complex things, to divide the granularity appropriately, as we have previously said, to ensure the principle of a single duty. Hope that through our continuous accumulation and summary, our future study will be more and more simple, progress more and more quickly.

The subtle relationship between Java learning--jstl tags and el expressions

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.