JSP------>jsp Label Programming

Source: Internet
Author: User
Tags tld

JSP label Programming One, Overview:
    • To further reduce the Scriptlet code in JSP pages, you can use JSP label programming techniques to achieve the goal
    • Just as there are many class libraries in the Java language, JSP tags also have tag libraries: Many open source components now implement the JSP tag library, developers just need to introduce the corresponding open source components in their own project, they can directly use the tags in the library provided by the tag to program, The principle is similar to calling the Java API in your Java program.
Second, how to define their own JSP tag, and form their own JSP tag library
    • Step1, store the jar packages needed to develop JSP tags into the classpath path
        •  
    • Step2, write the corresponding Java class, inherit the Javax.servlet.jsp.tagext.TagSupport class
    • Step3, overwrite the corresponding member method in the TagSupport class, such as doStartTag ()
    • STEP4, write the label description file *.tld, which defines the label name, Introduction, processing class, the various attributes used by the label, etc.
    • STEP5, Name Mapping for all *.tld files in Web. XML in your project
        • Name Mapping of all JSP tag libraries to be used in project in Web. xml
        • There are many benefits to doing so:
          • First, when the *.tld path is longer, you can reduce the amount of code because you only need to fill in the full path in Web. XML, and the JSP file uses the mapped name in the Web. XML directly to introduce the corresponding tag library (i.e., *.TLD)
          • Second, when *.TLD changes (such as name change, path change, etc.), do not need to change all the JSP files referencing the tag library, only need to modify the corresponding mapping in Web. XML (only need to ensure that the mapping name is not changed, the JSP file does not need to change)
    • STEP5, introduce a custom JSP tag library (that is, *.TLD) in the JSP file, and then use one or some of the tags defined in *.tld in the JSP page
Third, the introduction of three-party open source components, direct use of other people have implemented the JSP tag library, referencing the label to write their own JSP files

JSP------>jsp Label Programming

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.