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