SoFunction
Updated on 2025-04-14

JSP Custom Tags Page 2/3


6. How to process tags by TagSupport:

The class provides two methods to handle tags:

public int doStartTag() throws JspException
public int doEndTag() throws JspException

: However, when the JSP container encounters the start flag of the custom tag, it will call the doStartTag() method.

The doStartTag() method returns an integer value to determine the subsequent process of the program.

.SKIP_BODY: indicates that the content between ?>… is ignored

.EVAL_BODY_INCLUDE: Indicates that the content between the tags is executed normally

: However, if the JSP container encounters the end flag of the custom tag, it will call the doEndTag() method. The doEndTag() method also returns an integer value to determine the subsequent process of the program.

.SKIP_PAGE: Indicates that the web page is executed immediately, and the unprocessed static content and JSP programs on the web page are ignored. Any existing output content is immediately returned to the client's browser.

B.Tag_EVAL_PAGE: Indicates that the JSP web page will be executed according to the normal process.

7. User-defined tag properties:

If a custom attribute is also included in the tag, this attribute should be used as a member variable in the tag processing class, and methods for setting and reading attributes should be provided respectively.

8. Steps to create a tag processing class:

1. Create a file containing static text of JSP web page (that is, the text to replace the custom JSP tag)

2. Load static text when web application starts

3. Create a tag processing class

9. How to create a file containing static text of JSP web pages:

1. Use classes to store static text that you want to replace custom JSP tags in the web page

A class represents a collection of properties whose instances can be saved to or loaded from the stream. These texts are stored in the WEB-INF directory in the form of key/value. For example, key=value. In the property list, these key/values ​​are of type String

10. Common APIs of Properties:

(String key, String value): Call the put method of the Hashtable class to add attributes

(String key): Get the attribute value corresponding to the key in the attribute list

(InputStream in): Read the property list from the input stream object InputStream (Properties list)

(OutputStream out,String coMMent): Use the appropriate format to write the attribute pairs of the attribute list into the output stream object. By default, the ISO-88590-1 encoding format is used to process the input in rows. The key/value of the attribute is paired with "=,:", and the key/value pairing is separated by carriage return and line breaks.

11. Common APIs of ServletContext class:

(String uripath): Returns the ServletContext object represented by uripath in the server

(String name): Returns the value of the name parameter in the ServletConfig object

(String file): Returns the MIME type of the file represented by the file parameter

(String path): Returns the RequestDispacher object represented by path

(String path): Returns the resource corresponding to path in the form of an input stream. The object in the input resides can be any form of data. The path parameter must start with "/" and relative to the Context Root

12. How to use ServletContxt to read and save properties files:

1. Create class objects

2. Get the ServletContext object

3. Read the attribute file into an input stream object as an input stream

4. Load the input stream object into the Properties object

5. Save the Properties object to the ServletContext object
Previous page123Next pageRead the full text