Common jsp commands (compilation instructions/Action instructions)

Source: Internet
Author: User

Jsp contains three compilation commands and seven action commands.
Three compilation commands are: page, include, and taglib.
Seven action commands are: jsp: forward, jsp: param, jsp: include, jsp: plugin, jsp: useBean, jsp: setProperty, jsp: getProperty.
I. Compile commands
1. page command
A. Usually located at the top of the jsp page, the same page can have multiple page commands. The syntax format is as follows: Copy codeThe Code is as follows: <% @ page
[Language = "Java"]
[Extends = "package. class"]
[Import = "package. class I package .*},... "]
[Session = "true I false"]
[Buffer = "none I 8kb I size kb" 1
[AutoFlush = "true I false"]
[IsThreadSafe = "true I false"]
[Info = "text"]
[ErrorPage = "relativeURL"]
[ContentType = "mimeType [; charset = characterSet]" I "text/html; charset =" 808859-1 "]
[IsErrorPage = "true I false"]
%> 〉

1) The language attribute, generally java, represents the scripting language used on the jsp page.
2) Extends attribute: determines the Java class generated during JSP program compilation, the parent class to be inherited, or the fully qualified class name of the interface to be implemented.
1. The import attribute is used to import packages. The following packages are automatically imported by default and do not need to be explicitly imported. Default imported packages include:Copy codeThe Code is as follows: java. lang .*
Javax. servlet .*
Javax. servlet. jsp .*
Javax. servlet. http .*

2. Set the Session attribute to determine whether HTIP session is required for this JSP page.
3. The buffer attribute specifies the size of the output buffer. The internal JSP object of the output buffer: out is used to cache the output of the JSP page to the client browser. The default value is 8 kb. It can be set to none or another value, in kb.
4. autoFlush attribute: whether to force the output buffer content when the output buffer is about to overflow. If set to true, the output is normal. If set to false, an exception occurs during buffer Overflow.
5. Set the information of the JSP program in the Info attribute. You can use Servlet. getServletInfo () to obtain the value. If you are on a JSP page, you can directly call the getServletInfoO method to obtain the value, because the JSP page is essentially a Servlet.
ErrorPage attribute, which specifies the error handling page. If an exception or error occurs in this program and the JSP page does not have the corresponding processing code, the JSP page specified by this instruction is automatically called. When Using JSP pages, you can ignore exceptions, even if they are checked exceptions. (Redirect to the corresponding error handling page, but the URL is still the original URl and does not change.) If the page does not have this attribute, once the code encounters a problem, an error is prompted in the development environment and IE browser. It can be seen that this attribute controls the effect of exception handling in the form of better performance.
6. Set the IsErrorPage attribute to whether the JSP page is an error handler. If the page itself is an error handling page, you do not need to use the errorPage attribute.
7. The ContentType attribute is used to set the file format and encoding method of the generated webpage, that is, the MIME type and the page character set type. The default MIME type is text/html; the default character set is ISO-8859-1.
2. include command
The include command can be used to embed an external file into the current JSP file and parse the JSP statement on this page (if any ). This is a static include language, and does not check the changes of the included JSP pages.
Include can contain both static text and dynamic JSP pages. The static compilation command include is to add included pages to generate a complete page.
Include:
<%@ Include file = "relativeURLSpec" %> 〉
If the embedded file needs to change frequently, we recommend that you use the <jsp: include> operation command because it is a dynamic include statement.
After the jsp page containing the include instruction is deployed, the java file is generated after access to the compilation, the corresponding java files are generated under the "work \ Catalina \ localhost \ project \ org \ apache \ jsp" Directory of tomcat. These files have the same name as jsp files, it contains the compiled code, and even the code of another jsp contained in the include is added accordingly.

Ii. Action commands
1. forward Command: The forward command is used to forward page Response Control to another page. It can be forwarded to static HTML pages, dynamic JSP pages, or Servlet in the container.
The format of the JSP forward Command is as follows:
For JSP 1.0, use the following syntax:Copy codeThe Code is as follows: <jsp: forward page = "{relativeURL | <% = expression % >}"/>

You can use the following syntax:Copy codeThe Code is as follows: <jsp: forward page = "{relativeURL | <% = expression % >}">
{<Jsp: param... />}
</Jsp: forward>

The second syntax is used to add additional request parameters when forwarding. The added request parameter value can be obtained through the getParameter method of the HttpServletRequest class.

2. include command. It is a dynamic command that can be used to import a page. Its import will check the changes on the imported page each time. The format of the include command is as follows:Copy codeThe Code is as follows: <jsp: include page = "{relativeURL | <% = expression % >}" flush =" true "/>

Or:Copy codeThe Code is as follows: <jsp: include page = "{relativeURL | <% = expression % >}" flush =" true ">
<Jsp: param name = "paramName" value = "paramValue"/>
</Jsp: include>

The flush attribute is used to specify whether the output cache is transferred to the imported file. If it is specified as a drama. It is included in the imported file. If it is set to false, it is included in the original file. For earlier versions of JSP 1.1 or earlier, it can only be set to false.
<Include> and <jsp: include> are static and dynamic imports respectively. Their difference: static import completely inserts the code on the imported page. The two pages generate a complete Servlet, while dynamic import uses dynamic import in the Servlet to introduce the page.

3. useBean, setProperty, and getProperty commands
These three commands are related to JavaBean. useBean is used to initialize a java instance on the jsp page, setProperty is used to modify the attributes of the JavaBean instance, and getProperty is used to obtain the attributes of the JavaBean instance.
Syntax format of useBean:Copy codeThe Code is as follows: <jsp: useBean id = "" class = "" scope = "page | request | session | application">

Id is the Instance name of JavaBean. The class attribute determines the implementation class of JavaBean. Scope attribute determines the survival range [page, request, session, application]
Syntax format of setProperty:Copy codeThe Code is as follows: <jsp: setProperty name = "" property = "" value = ""/>

Name attribute needs to be set

4. plugin command
The plugin command is mainly used to download the server-side JavaBean or Applet and execute it on the client. Because the program is executed on the client, the client must install the virtual machine.
The syntax format of plugin is as follows:Copy codeThe Code is as follows: <jsp: plugin type = "bean | applet"
Code = "classFileName"
Codebase = "classFileDiretoryName"
[Name = "instanceName"]
[Archive = "URLtoArchive"]
[Align = "bottom I top I middle I left I right"]
[Heigh = "displayPixels"]
[Width = "displayPixels"]
[Hspace = "leftRightPixels"]
[Vspace = "topBottomPiexels"]
[Jreversion = Maid number | 1.2 "]
[Nspluginurl = "URLToPlugin"]
[Iepluginurl = "URLToPlugin"]>
[<Jsp: parames>
[Jsp: param name = "parameterName" value = "parameterValue"/>]
</Jsp: params>]
[<Jsp: fallback> text message for user that can no see the plugin
</Jsp: fallback>]
</Jsp: plugin>

These attributes are described as follows:
Type: specifies the Type of the java program to be executed. Is it a bean or an applet?
Code: Specifies the name of the file to be executed. The attribute value must end with the ". class" extension.
Codebase: Specifies the directory of the file to be executed.
Name: Give the program a Name to identify the program.
Archive: Specifies the path of the class to be used to be preloaded.
(Heat map, Vspace): displays the left and right white spaces.
Jreversion: the JRE version required for correctly running the program.
Nsplugin, ieplugin: Netscape Navigator, the address of the JRE required to download and run Internet Exploer.
<Jsp: fallback> command: When the applet cannot be correctly displayed, the displayed prompt is replaced.

5. param commands
The param command is used to set the parameter value. This command cannot be used independently because it is meaningless to use it independently. It can be used together with the following commands
Jsp: include
Jsp: forward
Jsp: plugin

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.