Control dynamic servlet graphic processing (2)

Source: Internet
Author: User

Compile custom JSP tags
Now that we understand how the Web server processes JSP page requests, let's look at how to implement custom JSP tags. Note: JSP tags come from both Standard libraries (such as Java Standard Template Library and JSTL) and Self-compiled libraries (also known as custom tags ). Generally, custom tags are used to handle special problem areas. For this article, we are working on how to manage images. Currently, Java 2 Extended Edition (J2EE) V1.2 and V1.3 use JSP specification V1.2. At the time of writing this article, Sun has released the JSP Specification V2.0. This new specification does not make major changes to methods that implement custom marking.
Using the taglib pseudocommand, You can import standard and custom tag libraries to the JSP page, as shown below:
<% @ Taglib uri = 'imagesizer. tld 'prefix = 'util' %>
This pseudo-command specifies the location of the mark library descriptor file. Here it specifies imagesizer. tld and the prefix when it is used on the page. Here it specifies util. As shown in the preceding tag example, the tag is used with its prefix and its name:
<Util: imagesizer src = "images/LazyDog.jpg"/>
Tag library descriptors tell Web containers which tags are available and how they work. Listing 1 shows an example. The file is in XML format and is easy to read. The Application development platform, such as IBM WebSphere Studio Application Developer, can help you fill fields and verify the file. The most important information is the tag element, which defines the names of custom JSP tags and Java classes for implementing tags. It also displays any attributes and subject content that are marked for acceptance.
Listing 1. Tag Library Descriptor (TLD) excerpt
<Taglib>
<Tlibversion> 1.0 </tlibversion>
<Jspversion> 1.1 </jspversion>
<Tag>
<Name> imagesizer </name>
<Tagclass> tags. ImageSizerTag </tagclass>
<Bodycontent> empty </bodycontent>
<Attribute>
<Name> src </name>
<Required> required </required>
</Attribute>
<Attribute>
<Name> alt </name>
</Attribute>
<Attribute>
<Name> quality </name>
</Attribute>
</Tag>
</Taglib>
In this example, a tag has three attributes, of which only the src attribute is required. The optional alt attribute simulates the img alt attribute of HTML. As an exercise, you can extend the JSP tag to include other optional img attributes. (There are about 12 of these attributes .) Finally, the implementation provides an optional quality attribute so that page writers can control the granularity and size of the images that have been re-adjusted.

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.