JSP programming topic 2 JSP core three (custom El functions and tags)

Source: Internet
Author: User
Tags tld

1. Custom El Functions:

A, custom classes, methods in the class are decorated with the static modifier:

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/981fae6f79844dd128ca0847106b2d67.png "title=" 00.png "alt=" 981fae6f79844dd128ca0847106b2d67.png "/>


B, this class, and functions, need to be registered in an XML file with an extension of. TLD (Tld,tag library definition, tag library definitions).

-It is important to note that the XML file needs to be constrained, that is, to configure the file header. This header constraint can be copied from the following files: In the Tomcat installation directory: TOMCAT-7.0\WEBAPPS\EXAMPLE\WEB-INF\JSP2.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/7b6f5df94de8c801c03db6b18049d0ea.png "title=" 01.png "alt=" 7b6f5df94de8c801c03db6b18049d0ea.png "/>


-Create a new XML file in the project's Web-inf directory (the name can be customized), add and modify the following:

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/23/c63e450ddcff807d5c052603167b3136.png "title=" 03.png "alt=" C63e450ddcff807d5c052603167b3136.png "/>


C, in the JSP file used to this El function, you need to add the taglib tag, as follows: (Add the Taglib label and how to use it)

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/f1e855c7fe56fafc1d39a6835434e784.png "title=" 05.png "alt=" F1e855c7fe56fafc1d39a6835434e784.png "/>

-An uppercase "ABC" is rendered in the page displayed by the browser.

-It should be noted that the El function can only handle attribute values and string constants in four fields:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/a09d9e3b27b9764d26fcba7a5417d73e.png "title=" 07.png "alt=" A09d9e3b27b9764d26fcba7a5417d73e.png "/>


2. El function in Jstl:

A, Jstl:apache has defined a set of standard tag library specifications, called JSTL,JSP standard Tag Library, which is the JSP standards tag libraries, the specification has passed JCP audit identified.

-In Jstl, a set of function tag libraries for string processing has been defined, and the function tag library defines 16 functions for string processing. We can use it directly in the JSP page.

-Of course, to use JSTL, you first need to import its jar package. (Jar package: http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/)

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/23/6f9454d67685b990fc79cbdfaa0e504d.png "title=" 06.png "alt=" 6f9454d67685b990fc79cbdfaa0e504d.png "/>


B, Jstl's El function tag library:

-The. tld file for the JSTL function tag library is stored in the Meta-inf directory of the standard jar package, and the file name is Fn.tld.

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/eab46254785d5a3781b30f95bb521051.png "title=" 08.png "alt=" Eab46254785d5a3781b30f95bb521051.png "/>


The 16 El functions defined in the C, Jstl function tag library are shown in the following table:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/e394c39e8a66454926111768abb2c3c6.png "style=" float: none; "title=" 09.png "alt=" E394c39e8a66454926111768abb2c3c6.png "/>

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/8af8d527d25762b8475c488bae4c8687.png "style=" float: none; "title=" 10.png "alt=" 8af8d527d25762b8475c488bae4c8687.png "/>


3. Custom El Tags:

A, a custom class that inherits the Simpletagsupport class and overrides the Dotag method:

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/17a7979bdca28a39ef4bfe4618a6d550.png "title=" 11.png "alt=" 17a7979bdca28a39ef4bfe4618a6d550.png "/>

-Javax.servlet.jsp.tagext.SimpleTagSupport class: The base class for defining the label processor, which implements the self-simpletag interface.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/258933b63e02cb929a611c30362f6924.png "title=" 12.png "alt=" 258933b63e02cb929a611c30362f6924.png "/>

-The Dotag () method of this class defaults to no processing of labels:

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/23/267d8cb9734bb988aeeb5a96e94ba9e6.png "title=" 13.png "alt=" 267d8cb9734bb988aeeb5a96e94ba9e6.png "/>

-Javax.servlet.jsp.tagext.JspFragment's Invoke (Writer out) method: Executes the JSP fragment and writes the data to the given character output stream: (if the passed parameter is NULL, The Getout method of the Jspcontext object associated with this fragment will be called and return the JspWriter class object as a parameter passed to the invoke (Writer out) method)

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/de2d30cba18339f4228cf4218439788e.png "title=" 14.png "alt=" De2d30cba18339f4228cf4218439788e.png "/>


b, create a new XML file under the Web-inf directory of the project (name can be customized), add and modify the following:

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/23/475c69fc830693f26715bc31cc37e0ff.png "title=" 15.png "alt=" 475c69fc830693f26715bc31cc37e0ff.png "/>


C, in the use of the El tag jsp file, you need to add the taglib tag, as follows: (Add the Taglib label and how to use)

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/23/a92573dd9ef3af555f0ad05b0c621506.png "title=" 16.png "alt=" A92573dd9ef3af555f0ad05b0c621506.png "/>


4. Customize tags with attributes:

A, custom class, which inherits the Simpletagsupport class, overrides the Dotag method: (writes the privatized member variable (and provides the Set method) in the custom class, equivalent to setting the property in the label processor

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/61797fb5cabdb62eb6c27e139653552b.png "title=" 00.png "alt=" 61797fb5cabdb62eb6c27e139653552b.png "/>


b, create a new XML file under the Web-inf directory of the project (name can be customized), add and modify the following:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/bfacb9c212670ccde4b8866ae7c11000.png "title=" 01.png "alt=" Bfacb9c212670ccde4b8866ae7c11000.png "/>


C, in the use of the El tag jsp file, you need to add the taglib tag, as follows: (Add the Taglib label and how to use)

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/62dc6ed6f94c08b60e1768e35bb079c5.png "title=" 04.png "alt=" 62dc6ed6f94c08b60e1768e35bb079c5.png "/>


5, custom Traversal list of Foreachlist tags:

A, a custom class that inherits the Simpletagsupport class and overrides the Dotag method:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/8e5841486a2bc34c2f8f2d487b20eb6d.png "title=" 05.png "alt=" 8e5841486a2bc34c2f8f2d487b20eb6d.png "/>


b, create a new XML file under the Web-inf directory of the project (name can be customized), add and modify the following:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/23/aeeafee4b6a13b232cdd0b633135629d.png "title=" 06.png "alt=" Aeeafee4b6a13b232cdd0b633135629d.png "/>

C, in the use of the El tag jsp file, you need to add the taglib tag, as follows: (Add the Taglib label and how to use)

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/23/aa1d897788a08618ea57def9f8647e35.png "title=" 07.png "alt=" Aa1d897788a08618ea57def9f8647e35.png "/>


6. Custom traverse the custom traversal collection with the foreach label of the array (including the base type array):

A, a custom class that inherits the Simpletagsupport class and overrides the Dotag method:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/cc0c1f52f41c7d48c26c1d3dfdefa31e.png "title=" 19.png "alt=" Cc0c1f52f41c7d48c26c1d3dfdefa31e.png "/>

-Java.lang.reflect.Array class: This class provides static methods for dynamically creating and accessing Java array objects.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/46cd10359aa0b2a0484fe7d18b9ed74f.png "title=" 20.png "alt=" 46cd10359aa0b2a0484fe7d18b9ed74f.png "/>


-EntrySet method in the Java.util.Map interface: used to return a set view containing the current map key value pair: (i.e., stored as "key = value", i.e. map.entry<k,v>)

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/23/ca3259349a6c739fb040467f492e0f31.png "title=" 10.png "alt=" Ca3259349a6c739fb040467f492e0f31.png "/>


b, create a new XML file under the Web-inf directory of the project (name can be customized), add and modify the following:

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/23/1d59c0ee5ab9fa830bbbd6ea5a57868b.png "title=" 21.png "alt=" 1d59c0ee5ab9fa830bbbd6ea5a57868b.png "/>


C, in the use of the El tag jsp file, you need to add the taglib tag, as follows: (Add the Taglib label and how to use)

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/2e3404d54d434f9b87a049c1ffd4f5bc.png "style=" float: none; "title=" 22.png "alt=" 2e3404d54d434f9b87a049c1ffd4f5bc.png "/>

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/23/c59c631cb7da7e0e2f405d6ae5f6ea08.png "style=" float: none; "title=" 23.png "alt=" C59c631cb7da7e0e2f405d6ae5f6ea08.png "/>



-the data displayed in Index.jsp is:

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/23/ba16ae061c57af59b5b73e8a22824327.png "title=" 24.png "alt=" Ba16ae061c57af59b5b73e8a22824327.png "/>

-Additional instructions: El Summary

-El cannot appear in the dynamic Code section of a JSP such as a Java code block, an expression block, and so on.

-El can only get data from the PageContext, request, session, and application four domain attribute spaces.

-El cannot throw a null pointer exception. If you access the properties of a null object, nothing is displayed.

-El does not throw array access out of bounds exception. If you access a non-existent element in an array, nothing is displayed.

-El does not have the ability to process strings, even simple string concatenation is not possible.









This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1975416

JSP programming topic 2 JSP core three (custom El functions and 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.