Summary of jsp tags and instructions

1.jsp instruction: three

It does not do any human actions by itself, and instructs the web container to do some operations according to its content.

There are only three in total:

  • page command
  • Include directive: The @include directive is a static import, and the <jsp:include> directive is a dynamic addition
  • taglib directive

2. JSP commonly used tags. It is the default tag of the jsp system, no additional operation is required, as long as it is a jsp file, it can be used directly.

  • <jsp:include> tag  
  • <jsp:forward> tag  
  • <jsp:param> tag

3. JSTL tag library tags. It is the official custom label of the jsp system.

             (1) Expression control tags : out tag, set tag, remove tag, catch tag.
    (2) Process control tags : if tag, choose tag, when tag, otherwise tag .
    (3) Loop tags : forEach tag, forTokens tag .
    (4) URL operation tags : import tag, url tag, redirect tag, param tag .

Customize all import operations

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

4.jsp custom tags.

The principle is to use the tld file to define the relationship between the tag and the java code (processing class). When the web container encounters a tag, it searches for the corresponding class and executes the java code.

<%@taglib uri="/tld file path" prefix="The name when the jsp page is referenced, define it yourself, for example: azsjkk"%>

use

<azsjk:tag tag name [the attributes in the tag tag are optional]>

5.

Introduction to EL expressions

  The full name of EL is Expression Language. The main functions of EL:
  1. Acquiring data
    EL expressions are mainly used to replace script expressions in JSP pages to retrieve java objects and obtain data from various types of web domains. (Objects in a certain web domain, access to properties of javabeans, access to list collections, access to map collections, and access to arrays). As long as the objects that can be accessed on this page can be accessed in ${}.
  2. Executing operations
    Using EL expressions, you can perform some basic relational operations, logic operations and arithmetic operations in JSP pages to complete some simple logic operations in JSP pages. ${user==null}
  3. Obtain common web development objects
    . EL expressions define some implicit objects. With these implicit objects, web developers can easily obtain references to common web objects, and thus obtain the objects in these objects. data. As long as the 11 hidden objects are page objects that you think the java code can call, it is fine.
  4. Calling Java methods
    EL expressions allow users to develop custom EL functions to call methods of Java classes through EL expressions in JSP pages. Generally speaking, the development and application of EL custom functions includes the following three steps:
  1. Write a static method of a Java class
  2. Write a tag library descriptor (tld) file, and describe the custom function in the tld file.
  3. Import and use custom functions in JSP pages

After writing the tag library description file, it needs to be placed in the <web application>\WEB-INF directory or any subdirectory under the WEB-INF directory except the classes and lib directories. 
  The <uri> element in the TLD file specifies the URI of the TLD file, and the tag library description file needs to be imported through this URI in the JSP file.
  The <function> element is used to describe an EL custom function, among which:
  The <name> sub-element is used to specify the name of the EL custom function.
  The <function-class> sub-element is used to specify the complete Java class name, and
  the <function-signature> sub-element is used to specify the signature of the static method in the Java class. The method signature must indicate the return value type of the method and the type of each parameter. Separate parameters with commas.

example:

${fn:filter("<a href=''>Point</a>")}

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=

Summary: All of the above have only one purpose: so that there is no java code in the jsp file!

Guess you like

Origin blog.csdn.net/socketyc/article/details/125472075