JSP best practices: Using JSTL to update JSP pages

Source: Internet
Author: User
Tags tld

Introduction: The JSP standard tag library (Standard tag Library,jstl) is a set of custom tags that implement many common Web site features in a standardized format. In the JSP best Practices Section, Brett McLaughlin will introduce you to Jstl, explaining how to transform your JSP pages to use highly functional markup.

One of the advantages of JSP technology is its custom tag library tool. In addition to the core JSP tags, such as jsp:include, the Custom Tag Library tool enables you to create unique markup to describe a site or application-oriented operation. Once you have created a custom tag library (taglib), you can reuse these tags when you extend the project or move to another project. You can also pass taglib to other developers so that they can be used on their own sites or in other parts of your Web application. In the next installment of this series, I'll show you how to create your own custom tag library, but now we'll focus on the JSP Standard Tag library (JSTL).

Jstl is actually a set of custom tag libraries that are standardized for JSP 1.2. Many jstl tags are similar to core JSP tags, but they can provide more functionality. For example, the c:import tag is very similar to the include and jsp:include instructions we introduced in the previous section (see Resources). Like the include directive, C:import can help you read (populate) pages of your Web site or Web application, but its functionality extends beyond the core JSP tags.

In the JSP best Practices Section, we'll use the c:import tag to learn how to transform a Web page from a JSP into a jstl. However, before we start using the new tag, we need to load the jstl into the Web container.

JSTL settings

Although the JSTL plan is bundled into the next wave of web containers, you must now set it yourself. Follow these steps to mount the Jstl into the Web container:

Download jakarta-taglibs-standard-current.tar.gz from apache.org.

Unzip the downloaded file.

Copy the Jakarta-taglibs/standard-1.0.3/tld/c.tld to the Web/inf/tlds directory.

Copies all jar files in the jakarta-taglibs/standard-1.0.3/lib to the Web-inf/lib directory.

Add the entries shown below to the Web-inf/web.xml deployment descriptor.   <taglib>
    <taglib-uri>http://java.sun.com/jstl/core</taglib-uri>
    <taglib-location>/WEB-INF/tlds/c.tld</taglib-location>
   </taglib>

Restart the Web container.

This is an express version of the Jstl setting, which can satisfy most situations. Please refer to the Resources section for more details.

Union JSTL Tag

If you want to use any jstl tag on a JSP page, you must first declare the tag library prefix and URL on the page. We are using the core Jstl library, so the standard prefix used is C (representing the core). Table 1 shows the Web site index file with the taglib Directive added:

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.