JSP simple exercise-JSP action commands

Source: Internet
Author: User

JSP simple exercise-JSP action commands

JSP action commands are often used in JSP programming. Unlike JSP commands, JSP action commands affect JSP operation!

1. include action commands:

The include action command is used to dynamically include a file in a JSP page. In this way, the page programs and the programs that contain the page are independent of each other and do not affect each other. JSP include action commands can contain a dynamic file or a static file. If a static file (such as a text file) is included, it is directly output to the client, which is displayed by the browser of the client. If a dynamic file is included, the JSP engine of the server is responsible for execution, and then the running result is returned to the client.

Note: The include action instruction is different from the include instruction. The latter is static inclusion, and a file is formed by combining the included file and the included file. The former is dynamic inclusion, and the principle is different, there are also differences in use.

The include action instruction format is as follows:

Or:

......

It can be seen that the effects of these two forms are the same when parameters are not required, and the second form is required if parameters are to be passed. If "file path" starts with "/", use the root directory path relative to the JSP server application. If the file name or folder name + file name is used, indicates the relative path of the current directory.

Note: When using dynamic files, you must note that the parameters and parameter values are passed.

2. forward action commands:

The forward action instruction is used to redirect a webpage, that is, to execute another webpage program from the forward action instruction of the current webpage. The syntax of forward action commands is as follows:

Or:

......


The value in the page parameter is the file to be switched to. It can be the path relative to the application server or the path relative to the current directory. If the webpage to be switched to is a dynamic webpage, for example, JSP files can pass parameters.

Note: You can also use the response. sendRedirect (destination URL) method to redirect between pages. response is the built-in object of JSP.

3. param action commands:

Param action commands are used to pass parameters to dynamic pages to be included or to be switched. Param application example:

 <% @ Page contentType = "text/html; charset = gb2312" %><% // Param application example Java program piece String s = null; s = "Lest's go! "; %>
            
        
 
 <% @ Page contentType = "text/html; charset = gb2312" %><% Out. println ("the value of the received parameter s is:" + request. getParameter ("s"); %>
4. plugin action commands:

This action command is used to load Java applet in JSP. The syntax format of the plugin Action Command is as follows:

    
  
   
Prompt message about whether the client browser supports plug-in download
  
 
In the preceding syntax format, the code parameter refers to the bytecode file compiled by the applet. The extension is. the class; codebase parameter specifies the location of the bytecode file. It can be a relative or absolute path, but the file name is not required in this parameter. You only need the directory path. If the bytecode file is in the same directory as the called JSP file, this parameter can be omitted. Among them, the jreversion parameter indicates the virtual machine version number for running the applet; the width and height parameters show the width and height of the result of a small program running; ... The parameter in is the prompt information.

5. useBean action commands:

This is a very important command used to create and use a JavaBean in JSP. In actual projects, JavaBean is often used for component development. In JSP, you only need to declare and use this component, so that static content and dynamic content can be separated to a large extent, this is also a bit of JSP. The syntax format of JavaBean in JSP is as follows:

Specifically, the id parameter is the name of the bean component in JSP. It can be called as long as it is within its valid range; scope is the valid range of bean, it has four values: page, request, session, and application. By default, the value is page, and the value is page, which indicates that the current JSP page and the static files contained in the current page are valid; if the value is request, the valid range is only in the request period. If the value is session, the value is valid in the session with each customer. If the value is application, all clients share the bean, this bean is not canceled until the server is closed. In the class parameter, if the class belongs to a certain package, the package name must be added before the class name, and "." can be referenced in the middle. Otherwise, you can directly use the class name.

6. setProperty action commands:

This action command is used to set the attribute values in Bean. The basic syntax format is as follows:

The setProperty action instruction can be used in the useBean action instruction or after useBean is declared, but cannot be used before the declaration. The format used in combination with useBean action commands is as follows:

......

7. getProperty action command:

The getProperty action command is used to obtain bean attributes and convert them to strings, and then output them on the JSP page. The format is as follows:


Related Article

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.