JSP seven big gestures

Source: Internet
Author: User

JSP seven big gestures 1) The Jsp:include directive is used to include a response from a servlet or JSP page during the request processing phase. Unlike the include in a compilation directive, include can only be used to contain static pages, while Jsp:include directives can contain static and dynamic pages. Format:

Java code

    1. 1.<jsp:include page= "file path"/>--------(Static page)
    2. 2.<jsp:include page= "file path" >--------(Dynamic page)
    3. <jsp:param name= "parameter name 1" value= "argument value 1"/>
    4. .....
    5. <jsp:param name= "parameter name n" value= "argument value n"/>
    6. </jsp:include>

2) The Jsp:forword instruction is used to perform a page turn and forward the processing of the request to the next page. Format:

Java code

    1. 1.<jsp:forword page= "file path"/>------(jump to static page)
    2. 2.<jsp:forword page= "file path" >------(Jump to dynamic page)
    3. <jsp:param name= "parameter name 1" value= "argument value 1"/>
    4. .......
    5. <jsp:param name= "parameter name n" value= "argument value n"/>
    6. </jsp:forword>

3) The Jsp:usebean directive is used to create a JavaBean instance format within a JSP page:

Java code

    1. <jsp:usebean id= "JavaBean name" scope= "valid range" class= "package Name" ></jsp:useBean> "class name"

Description: The id attribute specifies the name of the JavaBean, which can be used to invoke the name as long as it is within his valid range. The scope property is the valid range of JavaBean (four major ranges: request, page, session, application), and the class attribute specifies the classes (package name, class name) to which JavaBean belongs. 4) The Jsp:setproparty directive is used to format the property of the Bean object:

Java code

    1. 1.<jsp:setproparty name= "JavaBean name" proparty= "*"/>
    2. 2.<jsp:setproparty name= "JavaBean name" proparty= "property name"/>
    3. 3. <jsp:setproparty name= "JavaBean name" proparty= "attribute name" param= "parameter name"/>
    4. 4. <jsp:setproparty name= "JavaBean name" proparty= "property name" Value= "property value"/>

Description: proparty= "*" indicates that all values entered by the user in the JSP page are saved to match the properties of the JavaBean. When the Proparty has a specific value, it represents a property of the matching bean. The Param property represents a match to a property based on the parameters in the specified Request object. The Value property indicates that the Bean's properties are set using the specified values. 5) The jsp:getproparty instruction is used to read the properties of the Bean object and convert it to a string displayed on the page. Format:

Java code

    1. <jsp:getproparty name= "Bean name" proparty= "property name"/>

6) Jsp:plugin instruction (not commonly used) is used to download server-side JavaBean or applets to client execution. 7) Jsp:param directives (not commonly used) are used to set parameters and cannot be used alone, mainly in Jsp:include Jsp:forword jsp:plugin directives. Note: Both the include directive and the include action enable the ability to include external documents in a JSP document, and the names are similar and are easily confused. What is the difference between the include directive and the include action, and which one is better? (1). Include directives include JSP code that can be inserted before the JSP page is converted to a servlet. Its main advantage is its powerful functionality, which contains code that can contain JSP constructs that affect the main page in general, such as attributes, method definitions, and document type settings. Its disadvantage is that it is difficult to maintain as long as the included pages change, you have to change the main page, because the main page does not automatically see whether the contained pages have changed. The syntax format of the include directive is as follows

Java code

    1. <%@ include file= "Relative Url"%>

(2) The Include Action Jsp:include action is to include the output of the secondary page when the main page is requested. Although the output of a contained page cannot contain JSPs, these pages can be the result of other resources. The server interprets the URL that points to the contained resource in a normal way, so the URL can be a servlet or JSP page. The server runs the contained page in the usual way, putting the resulting output in the main page, in a way that is consistent with the RequestDispatcher class's include method. The advantage is that there is no need to make changes to the main page when the included pages change. The disadvantage is that it contains the output of the secondary page, not the actual code of the secondary page, so there is no JSP construct that can affect the main page in general on the included page. The complete syntax for the Jsp:include action is as follows

Java code

    1. <jsp:include page= "Relative path to Resource" flush= "true" >

Where jsp:include cannot have spaces between them, the page property specifies which pages are included, which is required and is a relative URL that points to a resource. If the relative URL does not begin with/, it is interpreted as a path relative to the main page, and if it starts with a/, the URL is interpreted to be the root of the current Web application, not the root of the server, because the URL is interpreted by the server and is not interpreted by the user's browser. The following line of code, which is interpreted by the user's browser, is interpreted as relative to the server's root directory.

The Flush property is an optional secondary property, and the default value is False, which specifies whether the output stream of the main page should be emptied before the page is included.

Note: In JSP1.1, flush is a required property, and the party can only be true. (3). The difference between the two differs from the fundamental difference between the Jsp:include action and the include directive is the time that they are called. The Jsp:include action is activated during the request, while the include directive is activated during page conversion. The difference between the two determines the difference in their use. Pages that use the include directive are more difficult to maintain than pages that use jsp:include actions.

As already mentioned, using JSP directives, if the included JSP page changes, then all pages used in this page need to be updated manually. In the relevant specification of the JSP server, it is not required to be able to detect when the contained files change, in fact most of the server Pages have to implement this mechanism. This can lead to very serious maintenance problems, remembering all other pages that contain one page, or recompiling all the pages so that the changes take effect. At this point, Jsp:include has a huge advantage, which is to re-include resources in each request. The Jsp:include action should be used as much as possible in implementing the file inclusion.

The Jsp:include action is clearly superior to the include directive in terms of maintenance, while the include directive can still exist and naturally has special advantages in other respects. This advantage is that the include directive is more powerful and performs slightly faster. The include directive allows the included files to contain JSP code that affects the main page, such as the settings of the response submission and the definition of the property method. Knowing the functions and differences of jsp:include actions and include directives, when used, you can decide which method to use by considering various factors. Although each has a certain advantage and disadvantage, in practice, the use of Jsp:include action should be a priority, because its advantages in code maintenance far outweigh its lack of functionality.

Technology sharing: www.kaige123.com

JSP seven big gestures

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.