JSP Jstl component allows you to program with tags

Source: Internet
Author: User
Tags foreach count html tags microsoft frontpage

JSTL allows JSP programmers to use tags for programming rather than Java code. To illustrate why this is desirable, give a quick and easy example. Let's give a very simple example from 1 to 10. We use the regular Scriptlet JSP page and Jstl two ways to make this page. When the example of this number to 10 is compiled using Scriptlet JSP, the JSP page will have the following display:

< html>
< head>
< Title>count to ten in JSP scriptlet</title>

As you can see from the example above, the Web page source code generated using Scriptlet code includes a mix of HTML tags and Java statements. There are a number of reasons why this hybrid programming style is not optimal.

The main reason for mixing scriptlet and label based code is not the best choice is readability. This readability is for people and computers. JSTL allows programmers to look at a program that consists of an entire HTML and html-like tag.

The readability of JSP scriptlet code is not only applicable to humans. The combination of Scriptlet and HTML code is also difficult to read by the computer. In particular, HTML production tools such as some Dreamweaver and Microsoft FrontPage. Currently, most HTML production tools leave JSP Scriptlet code as non-editable chunks. HTML production tools usually do not directly modify the JSP Scriptlet code.

The following code shows how to use Jstl to write this example from 1 to 10. As you can see, the code list is more consistent because only the labels are used. Is an example of how HTML and JSTL tags are mixed together.

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

%>
< html>
< head>
< Title>count to Example (using JSTL) </title>

When you check the previous code, you can see that the JSP page is made up entirely of tags. The above code uses HTML tags such as < head> and < br>. The use of labels is not limited to HTML tags. This code also uses JSTL tags such as < c:foreach> and < c:out>. Introduce you to some JSTL basics in this article.

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.