Javaweb_ using the tag library to simplify JSP

Source: Internet
Author: User

A JSP tag library, also called a custom label.

Application scope

JSP tags, mainly used in the foreground page, in JSP, if there is <%%> Java code in JSP, then for the foreground developer, need to understand Java code.

How to develop the foreground and do not understand the Java code, the cooperation of development?

In the front page, most of the code is Html+css+javascript, suddenly a lot of Java code, it really makes people very embarrassed.

By introducing tags, some of the commonly used Java code is organized into something similar to <> in HTML. In front of the developer, it is better to look at a specific number of tags than Java code.

After all, what is JSP? The JSP is the servlet when the server starts, it compiles all the JSPs into *.class files. However, in this process, the JSTL tag also generates the corresponding Java code.

Now look at the classification of the tag library:

Core Tag Library

Format Tag Library

Function Tag Library

Database Tag Library

i18n Formatting Tag Libraries

1 , introduce Jar Package

Use of Tag libraries

2 , in JSP To use the tag library on the page, you first need to introduce the tag library.

in the JSP the first plus:

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

Content from:

With the above settings, you can directly use the

The use of the process involves the value of the data, that is, from the Request gets the data. The EL (expression Language) expression can be used at this time .

El Language Introduction The El language is a representation of the JSTL output (input) of a Java expression. In Jstl, the El language is used in the Jstl attribute value. The El language can only be called by establishing an expression ${exp1} .

Use Tags:  

Eg:hello ( using Tags ): <c:out value= "${hello}" ></c:out><br>

The specific use of the label, because too much, but also quite regular, in the process of Use please refer to the API documentation.

Of course, in some mature frameworks, there are also some tag libraries, because the framework of their own integration, so the framework of compatibility will be better. in General, using a tag library to encode can simplify the page. Makes the code simple and easy to read.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Javaweb_ using the tag library to simplify JSP

Related Article

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.