[Java Reading Notes] JSTL, quick master, java Reading Notes jstl

Source: Internet
Author: User

[Java Reading Notes] JSTL, quick master, java Reading Notes jstl

JSTL is not a novel technique and is very simple. Some people even think that JSTL is outdated. However, I think that since it exists, there is a truth. As a technician, you should know what they are, how they are used, and what advantages they have.


JSTL consists of the tag library and EL language. Next we will first introduce the tag library, then introduce the EL language, and finally summarize the advantages of JSTL.


JSTL

 

JSTL Introduction


JSTL (JSP Standard Tag Library) is a label provided by SUN to simplify JSP Page design. JSTL is composed of Core (Core library), Format (formatting Library), SQL (supporting database operations), XML (supporting XML operations), and Functions (function library) five tag libraries, the most important of which is the Core tag library and Format tag library ..


JSTL configuration and use


1. Configuration

Download the jar package containing jstl and copy jstl. jar and standard. jar to WEB-INF/lib.

2. Use

Use the taglib command to introduce the tag library. For example, introduce the core tag library.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

3. Use specific syntax

I will not talk about how to use the specific syntax. I recommend two very detailed blog posts: JSTL core tag library and JSTL details.


EL expression


EL Introduction


EL (Expression Language, JSP Expression Language) is introduced by JSTL1.0 for the first time and merged into JSP specifications. It is a very important component of JSP. If you only use the EL expression, you do not need to introduce any jar package, as long as the jsp/servlet container implements J2EE1.4/servlet2.4 and JSP2.0 specifications.


EL expression syntax


$ {EL Expression} // All expressions start with "$ {" and end with "}". EL uses the "[]" and "." operators to access data.

For the specific usage of EL, we recommend a classic blog post: EL expression.


Advantages of EL expressions


1. To make JSP writing easier.

2. Use EL expressions on the JSP page to simplify access to variables and objects.


EL expression usage


1. static text (static content)

Example: arithmetic operation: 10 + 5 =$ {10 + 5} <br>

2. Standard and custom tags

For example, tags in HTML

3. EL cannot be used in script elements.


Finally, we will attach an EL expression to respond to the request on the jsp page to help you understand the role of EL expression.




Advantages of using JSTL

JSTL has the following advantages:

1. Simplifying the page is conducive to maintenance and Avoiding writing Scriptlet in the page (Scriptlet is the Java code included between <%>)

When the project is very large, the java code of the jsp page must be rewritten every time, and a large amount of code will appear, which is not easy to maintain and modify and has poor readability, it is also a pain for art workers who do not understand java. JSTL labels can be reused infinitely, making the interface very simple and easy to maintain.

2. Implemented the idea of hierarchy

JSTL is more in line with the idea of layering and separates data from display. The artist is only responsible for page beautification, while the programmer is responsible for background logic code. JSTL makes the division of labor between the artist and the program clearer, simplified JSP and WEB application development.

3. JSTL is a standard developed by SUN. It does not depend on any framework. You only need to introduce the jar package and introduce it on the page!

......

Of course, JSTL has many advantages. We will introduce three key points.


Summary


The EL language is the representation of a JAVA expression from the JSTL output (input. Generally, when writing JSP pages, JSTL should be used with EL expressions to simplify pages, reduce java code of jsp pages, and implement the idea of layering.




Java jstl Problems

Directly used. java ee5 has built-in jstl, which can be written in this way when taglib is imported on the page.

<% @ Taglib uri = "java.sun.com/jsp/jstl/core" prefix = "c" %>

Small issues with jstl <c: if> in java

Yes
<C: if test = "$ {info. name eq xiaoming}">
Xiaoming is request. setAbtt .. ("xiaoming", xiaoming );

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.