JSP Simple practice-jsp action Instructions

Source: Internet
Author: User

JSP action instructions are often used in JSP programming, and unlike JSP directives, it will affect the function of JSP running!

1. Include Action instruction:

The Include action directive is used to dynamically include a file in a JSP page, so that the program containing the page and the containing page are independent of each other and are not affected. The Include action directive for a JSP can contain a dynamic file or a static file. If it contains a static file (such as a text file), it is directly output to the client, the client's browser is responsible for the display, if it contains a dynamic file, then the server's JSP engine is responsible for execution, and then return the results of the operation to the client display.

Note: The Include Action directive differs from the include directive, which is a static inclusion that combines a containing file with a contained file to form a file, while the former is dynamically included, with different principles and differences in use.

The Include action directives are in the following format:

<jsp:include page= "file path"/> or:

<jsp:include page= "file path" >

<jsp:param name= ' parameter name 1 ' value= ' parameter 1 ' value '/>

......

<jsp:param name= "parameter name n" value= "argument n" value "/>

</jsp:include>

As you can see, the effect of both forms is the same when you do not need to pass parameters, and the second form is used if you want to pass parameters. "File path" If you start with "/", the root path of the relative JSP server app is used, and if you use the file name or folder name + file name directly, it is the relative path to the current directory.

Note: When using, be aware that the values of parameters and parameters are passed only when they are contained in a dynamic file.

2. Forward Action instruction:

The forward action instruction is used to redirect the Web page from the Forward Action command on the current page to another Web program. The call syntax format for the forward action instruction is as follows:

<jsp:forward page= "file path"/> or:

<jsp:para name= ' parameter name 1 ' value= ' parameter 1 ' value '/>

......

<jsp:para name= "parameter name n" value= "argument n" value "/>

<jsp:forward>

Where the value in the page parameter is the file to be moved, either the path relative to the application server, or the path relative to the current directory, or if the page you want to turn to is a dynamic Web page, such as a JSP file, you can pass parameters.

Note: Redirects between pages can also be implemented using the Response.sendredirect (destination URL) method, response is a built-in object for the JSP.

3. param Action Instruction:

The param action instruction is used to pass parameters to dynamic pages that need to be included or to dynamic pages to be turned. PARAM Application Example:

<!--paramexample.jsp file--><%@ page contenttype= "text/html; charset=gb2312 "%>
<!--forparam file--><%@ page contenttype= "text/html;charset=gb2312"%>
4. Plugin Action instruction:

This action instruction is used to load Java applet applets in JSP. The syntax format for the plugin action instruction is as follows:

<jsp:plugin type= "applets" code= "applet class file" codebase= "applet location" jreversion= "Virtual machine version number" Width= "Applet display width" height= "Applet display height" >   <jsp:fallback>      Does the client browser support plugin download prompts   </jsp:fallback></jsp:plugin>
In the above syntax format, the code parameter refers to the small program compiled bytecode file, the extension of the. Class;codebase parameter indicates the location of the bytecode file, can be a relative path or an absolute path, but in this parameter does not require a file name, only the directory path is required. This parameter can be omitted if the bytecode file is in the same directory as the calling JSP file, where the Jreversion parameter indicates the version number of the virtual machine running the applet, and the width and height parameters show the widths and heights of the results of the applet running respectively; <jsp:fallback The parameters in >...</jsp:fallback> are informational.

5. Usebean Action Instruction:

This is a very important instruction to create and use a JavaBean in the JSP. In practical engineering, JavaBean is often used to do component development, but in JSP it is only required to declare and use this component, which can realize the separation of static content and dynamic content, which is one of the JSP's. The syntax format of JavaBean in JSP is as follows:

<jsp:usebean id= "Bean name" scope= "valid range" class= "Package name". Class name >

</jsp:useBean>

Where the ID parameter is the name of the bean component in the JSP, as long as it is within its valid range, this name can be used to invoke it; scope is the valid range of beans, it has four kinds of values, page,request,session,application, By default, the value is page, and a value of page indicates that the current JSP page and the current page contains a static file, the value of request means that the valid range is only during request, and the value is session is valid for each client's session A value of application means that all clients share the bean until the server shuts down. In the class parameter, if the class belongs to a package, add the package name in front of the class name, which is available in the middle. Reference, or you can use the class name directly.

6. SetProperty Action Instruction:

This action instruction is used to set the value of the attributes in the bean, with the following four basic syntax formats:

<jsp:setproperty name= "Bean name" property= "*"/>

<jsp:setproperty name= "Bean name" property= "property name"/>

<jsp:setproperty name= "Bean name" property= "property name" param= "parameter name"/>

<jsp:setproperty name= "Bean name" property= "property name" Value= "property value"/>

The setproperty action instruction can be used in the Usebean action instruction, or it can be used after the Usebean is declared, but cannot be used before the declaration. The format used in conjunction with the Usebean action instruction is as follows:

<jsp:usebean id= "Bean name" scope= "valid range" class= "Package name". Class name >

<jsp:setproperty name= "Bean name" property= "property name" Value= "property value"/>

......

<jsp:setproperty name= "Bean name" property= "property name" Value= "property value"/>

</jsp:useBean>

7. GetProperty Action Instruction:

The GetProperty action instruction is used to obtain the bean's properties and convert it to a string, and then output it in the JSP page. Use the following format:

<jsp:getproperty name= "Bean name" property= "property name"/>


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.