JSP programming topic 2 JSP Core one (built-in object, JSP instruction and JSP action)

Source: Internet
Author: User

1, JSP built-in objects:

-a reference that can be used directly in a JSP's Java code block, an expression block, and so on, called a built-in object of a JSP. There are 9 commonly used built-in objects, namely:

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/20/32cacd3b3bfe2a3b3235e49f6ee2ad93.png "title=" 00.png "alt=" 32cacd3b3bfe2a3b3235e49f6ee2ad93.png "/>

-These nine objects can be used directly in the JSP's Java code block, expression block. Can be used directly because Java code blocks and expression blocks are translated by the JSP engine into the _jspservice () method of the servlet. And these nine objects are local variables in the _jspservice () method. The code in the JSP's Java code block, the expression block, is the code in the _jspservice () method, so it can be used directly in it. (See the Java EE Help documentation for detailed usage of built-in objects, not here.) )


2. JSP directive: (Directive)

-The role of the JSP directive is to make some basic property settings for the current page, providing a basic environment for the current page to run.

-Depending on the functionality, the JSP contains three types of directives: page instruction, the pages directive, the include directive, which contains the instruction, and the taglib instruction, the tag Library directive. Regardless of the type of instruction, the syntax format used is as follows:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/20/1a6947b46de236e1a529303eb2b647d4.png "title=" 03.png "alt=" 1a6947b46de236e1a529303eb2b647d4.png "/>


A, page directive:

-the page directive is used to set information about the current JSP page. A JSP file can contain multiple page directives. The properties of the common page directive are as follows:

-pageencoding Property: The Pageencodings property is used to set the character encoding format used by the current JSP page. That is, the user in the browser by right-clicking to view the encoding is the encoding format seen. Such as:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/20/538577638d16e2ee22818af396e754f5.png "title=" 04.png "alt=" 538577638d16e2ee22818af396e754f5.png "/>

-the statement that is translated into the servlet by the JSP translation engine is the Setcontexttype () method in the _jspservice () method:

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/20/c7ca133a967c656b071bf6e2398adf4a.png "title=" 05.png "alt=" C7ca133a967c656b071bf6e2398adf4a.png "/>


-ContentType property: The JSP translation engine translates this property in the page directive with the same effect as the translation Pageencoding property. The difference is that the ContentType property value can be set to other, such as the default setting contenttype= "Text/html;charset=utf-8", or it can be set to Contenttype= "text/xml;charset= UTF-8 ".


-Import property: Used to complete importing the specified class in the JSP page, which is translated by the JSP engine into the import statement in the servlet, for example:

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/21/0052e7b00c6cc1115b98849008b8490d.png "style=" float: none; "title=" 07.png "alt=" 0052e7b00c6cc1115b98849008b8490d.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/21/c0656d25609beac5374cb77345c47cab.png "style=" float: none; "title=" 08.png "alt=" C0656d25609beac5374cb77345c47cab.png "/>


B. include directive:

-include directive: the include directive, which is used to include the specified file in the current JSP file. The directive has only one property file, which specifies which files to include.

-There is only one property file in the include directive that specifies which files to include. (The File property value (path) is the dynamic part of the JSP file, which belongs to the background path, and the reference path is the root of the current Web project.) )


3. JSP action (Action):

-Extensive use of Java code blocks, expression blocks, and so on in JSP pages can make JSP pages look "cluttered". In order to make the JSP page look concise, in order to simplify the Java code, we generally use as few Java code blocks and expression blocks as possible. Instead, El expressions, jstl expressions, and JSP actions are used.

-JSP action refers to the use of system-defined tags to complete the functions that should be done by the Java code.

-The syntax format for JSP actions is:

650) this.width=650; "src=" Https://s2.51cto.com/oss/201710/21/94e4c8165e91a040e7f392f102cae31b.png "title=" 00.png "alt=" 94e4c8165e91a040e7f392f102cae31b.png "/>

Or:

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/21/280f1d27eb8b8969a5b4daabb358c4fd.png "title=" 01.png "alt=" 280f1d27eb8b8969a5b4daabb358c4fd.png "/>

-JSP is a lot of action, but in the actual development of the two commonly used: forwarding actions and include actions.

-The completion of these two actions is implemented using the Responsedispatcher forward () and the Include () methods in the underlying. The essential difference between these two request forwarding methods is that the standard output stream has a different opening time. The standard output stream of the forward () mode is the standard output stream that is turned on in the target resource, while the standard output stream of the include () mode is turned on in the page that currently emits the containing action. Therefore, the originating page of the forward () action cannot write data to the standard output stream, and the originating page of the include () action and the target page can write data to the standard output stream.

650) this.width=650; "src=" Https://s5.51cto.com/oss/201710/21/22d5923aebc81b7cc23ff1b6fd658083.png "title=" 05.png "alt=" 22d5923aebc81b7cc23ff1b6fd658083.png "/>

650) this.width=650; "src=" Https://s3.51cto.com/oss/201710/21/55c3dfacf9fcc4bf1a82a89be3020dc2.png "title=" 06.png "alt=" 55c3dfacf9fcc4bf1a82a89be3020dc2.png "/>

-All two actions have a page property that specifies which pages to turn to.


A, forward action:

-Once you have a forward action on the page, all the content in the current page will not be displayed. Because the page is forwarded directly to the next page.

650) this.width=650; "src=" Https://s4.51cto.com/oss/201710/21/49c60715a653d913569f711efeb06246.png "title=" 02.png "alt=" 49c60715a653d913569f711efeb06246.png "/>


B, include action: used to complete the ability to include the target page in the current page.

650) this.width=650; "src=" Https://s1.51cto.com/oss/201710/21/6e3ccab26d7c2e7d44bac7c768227559.png "title=" 03.png "alt=" 6e3ccab26d7c2e7d44bac7c768227559.png "/>


The difference between C, include action, and include directive:

-instruction element: the Include directive reads the contents of the specified page and merges the contents with the original page. Then go through two stages: translating JSPs into Servlets and Servelt to. class files. (in the file being introduced do not add the ContentType attribute because multiple contenttype cannot be specified in the JSP file.) )

-Action element: it does not add the code of the JSP to be added to the JSP that is added, just at run time to introduce the JSP page to be added after the execution of the answer, which means that we can specify any Web resources that can generate an answer (such as a servlet or a page), The JSP container executes the specified resource through an internal function call as long as the types produced by these resources are the same as the type of encoding produced by the JSP page (garbled if the encoding type is different). As a result, these introduced resources can help with the original request, so these resources can access all objects within the request scope, as well as all the original request parameters. (If you modify the JSP page that you want to add, you can immediately use the latest version of the page, because the page is treated in exactly the same way as a JSP page that is called directly by the browser, that is, the container detects the change in the page and automatically enters the translation phase to get the latest version of the page).

-The following are the differences between the two include two usages, mainly in two different ways:

On the execution time:

<%@ include file= ". JSP"%> is performed during the translation phase.

executed during the request processing phase.

In the introduction of the different content:

<%@ include file= ". JSP"%> introduces static text (html,jsp), which is incorporated into a JSP page before it is transformed into a servlet.

introduces the answer text generated by the execution page or servlet.

This article is from the "12392717" blog, please be sure to keep this source http://12402717.blog.51cto.com/12392717/1975018

JSP programming topic 2 JSP Core one (built-in object, JSP instruction and JSP action)

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.