js| Standard | tutorials | templates | Introduction to Introductory tutorials
The JSP Standard Template Library (JSTL) is a new component published by Sun Company for JSP Development. JSTL allows you to use tags (tags) for JSP page development, instead of using the Scriptlet code that most JSP programmers have grown accustomed to. Jstl can do almost anything that traditional JSP scriptlet code can do. You might wonder, why do we need another such HTML-generating language?
STL allows JSP programmers to use tags rather than Java code to program. To show why this is more advantageous, the following will show examples. We'll check a very simple JSP page from 1 to 10. We will examine in two ways, one is based on JSP Scriptlet, one is jstl. When the example of this counter page is written in JSP Scriptlet, the JSP page looks like this:
<title>count to ten in JSP scriptlet</title>
<body>
<%
for (int i=1;i<=10;i++)
{%>
<%=i%><br/>
<%
}
%>
</body>
As you can see in the previous example, the page source code generated with the Scriptlet code contains mixed HTML tags and Java statements. This hybrid programming approach is not the best way, and its main reasons are the following.
The main reason is its readability. This readability relies primarily on humans and computers. Jstl can allow programmers to view a page that contains only full HTML and HTML-like tags.
SP scriptlet code is not readable for humans. This mixed scriptlet and HTML code is also hard to read for computers. Especially for those HTML official tools such as Dreamweaver and Microsoft FrontPage, the visibility of the show is more prominent. Currently, most HTML official tools isolate JSP scriptlet code in the form of non-editable blocks (non-editable blocks). This HTML official tool is usually not directly modifying the JSP Scriptlet code.
The following code shows how this counter example can be written using the Jstl method. As you can see, this code list has invariance and only one tag is used. The HTML and JSTL tags are mixed together to produce this program.
<%@ taglib uri= "Http://java.sun.com/jstl/core" prefix= "C"%>
<title>count to Example (using JSTL) </title>
When you examine the code for the example above, you will see that the JSP page contains only the tags. The above code uses HTML tags such as
Install Jstl
To use JSTL, you must have a JSP1.2 (or later) container installed. The most common JSP container is Apache Tomcat. You can download it from http://jakarta.apache.org/tomcat/. Standalone Tomcat allows you to use regular JSP scriptlet code. To use JSTL, you must install Jstl in Tomcat. The main URL for Jstl is http://java.sun.com/products/jsp/jstl/. To use JSTL, you must unzip the file and then install it to the correct location of Tomcat.
To install Jstl in Tomcat, you have the following three steps:
Copy the Jstl jar file into the Tomcat's Lib directory.
If you are using Windows, the most likely location for the Lib directory is C:Program Filesapache Tomcat 4.0webappsrootweb-inflib. You should copy these jar packs to your Tomcat jar directory.
Copy jstl TLD files to Tomcat's Web-inf directory
When you check jstl publish files, you should notice that 8 files end with a TLD extension. All 8 files should be copied to your Web-inf directory.
Modifying the Web.xml file contains these TLD files.
Finally, you must modify your web.xml to add 8 tab libraries to the table entries (entry). The table entries that you need to add are as follows:
<taglib>
<taglib-uri>http://java.sun.com/jstl/fmt</taglib-uri>
<taglib-location>/WEB-INF/fmt.tld</taglib-location>
</taglib>
After completing these three steps, you can now prepare to test your JSTL installation. You can verify this by creating a JSP page that contains JSTL. One of the simplest example programs is the one above the counter program. You should place it in your Webroot directory (C:Program filesapache Tomcat 5.0webappsROOT). Once Tomcat is started, you should be able to view this page by browsing http://127.0.0.1:8080/count.jsp.
If you do not install JSTL correctly, you may not receive an error message. If Jstl does not explain your label, it will skip directly over the Web browser. The Web browser then interprets these unknown HTML tags. Most browsers simply ignore these unknown HTML tags.
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.