How to use custom tags in J2EE WEB component development

Source: Internet
Author: User
Abstract:
J2EE platform web component development involves SERVLET and JSP Technologies. Each SERVLET and JSP has its own advantages and disadvantages. JVAVABEAN and custom tags provide excellent extensions for JSP presentation capabilities, greatly improving the JSP presentation capabilities. At the same time, their introduction allows WEB development to work well and improve development efficiency, reduces development costs and improves the readability, reusability, and maintainability of JSP pages. This article describes how to use custom tags in J2EE WEB component development. It mainly introduces the significance of developing custom tags, principles, steps, release on TOMCAT, and a typical tag instance are provided to deepen understanding and improve the practical application. Retained the author and article source for reference.
Keywords:
J2EE, SERVLET, JSP, WEB components, custom tags.
I. Why use custom labels?
Anyone who has developed Servlet and JSP knows that from the presentation layer, Servlet and JSP are the technologies used to generate dynamic WEB content on the J2EE platform. They all produce the same results, however, they use different mechanisms to build WEB components. Sverlet embeds content in the logic, and carries the server processing logic, while JSP embeds the logic in the content.
Like HTML, JSP is tagged and suitable for content representation and description. However, JAVA scripts are required to process representation logic and business logic, however, the embedding of JAVA code greatly reduces the readability and maintainability of JSP page representation code, and is not conducive to reusability of repeated functions. The same Servlet is a JAVA class that implements specific interfaces. It is written in JAVA and highly programmed. It is suitable for processing representation logic and business logic, however, adding the page code that represents and describes the content in the Servlet makes the logic processing messy and has poor readability, and also brings disadvantage to the maintenance of the presentation content.
The introduction of JavaBean effectively solves the dilemma faced by JSP and Servlet, and enables the development of WEB components on the J2EE platform to achieve the separation of content and presentation logic and business logic. The JAVA code at the JSP page layer, the content description at the business logic layer, and the code representation can be separated.
However, JavaBean has inherent limitations. It is only reusable components. It encapsulates some data and business logic functions independently of the runtime environment and cannot obtain the runtime environment information.
The custom tag mechanism has been introduced in JSP 1.1 and JSP1.2 to solve the defects of JavaBean and completely remove the representation and business logic code in WEB component development, this greatly enhances code readability, maintainability, and reusability.
2. Communication between JSP pages and custom tags
Javax is introduced in JSP 1.1. servlet. jsp. tagext: When creating tags, you must implement specific interfaces or inherit the corresponding classes. The Tag interface defines the basic communication contract between the JSP page and the Tag processor, that is, the communication API interface. The JSP specification specifies the process by which WEB containers call these methods to process their communication, so as to manage the lifecycle of tags. The time sequence is shown below:
III. Principles of custom tags

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.