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.