Java Web Development--jsp Basic Grammar essays

Source: Internet
Author: User

In a JSP page, you can include instruction identification, HTML code, JavaScript code, embedded Java code, comments, and JSP action identifiers. But these are not necessary for JSP pages.


1 Instruction ID
The instruction ID is primarily used to set relevant information that is valid throughout the JSP page range. It is interpreted by the server to execute and does not produce any content output to the Web page.
The syntax format for JSP directive identifiers is as follows:
<%@ directive Name Property 1 = "Property value 1" Property 2 = "Property value 2" ...%>
Parameter description:
Directive Name: Used to specify the instruction name, including page, include, and taglib 3 directives in the JSP
Properties: Used to specify property names, and different directives contain different properties. In one instruction, you can set multiple attributes, separated by commas or spaces.
Property value: Used to specify the property value

1.1 page directive
The page directive is the most commonly used instruction in JSP pages to define the relevant properties of the entire JSP page, which is converted to the appropriate Java program code when the JSP is parsed by the server into a servlet.
<%@ page attr1= "value1" attr2= "value2" ...%>
1. Language properties
2. Extends properties
3. Import Properties
4. Pageencoding Properties
5. ContentType Properties
6. Session Properties
7. Buffer Property
8. AutoFlush Properties
9. Iserrorpage Properties
10. ErrorPage Properties

1.2 Include directives
The file contains the directive include, which allows you to include another JSP page in one JSP page. However, the directive is a static inclusion, that is, all the contents of the contained file will be included in the JSP page as is, even if the included file has JSP code, in the package Hanzhong will not be compiled to execute. With the include directive, you will eventually generate a file, so you cannot have a variable of the same name in the contained and contained files.
<% @include file= "path"%>
Note: When you apply the include directive for file inclusion, it is recommended that tags such as

1.3 taglib directive
In a JSP file, you can use the TAGLIB directive to identify the tag library that is used in the page, reference the tag library, and develop a label prefix. After you reference the tag library in the page, you can refer to the label in the tag library by using a prefix.
<% @taglib prefix= "TagPrefix" uri= "Taguri"%>


2 Script ID
In JSP pages, the script identifier makes it easy and flexible to generate dynamic content in a page.
The scripting identity of a JSP consists of 3 parts, the JSP expression declaration identity and the code fragment.

2.1 JSP expressions
Used to output information to the page in the following syntax format:
<%= expression%>
An expression can be a complete expression of any java. The result of the expression's final operation is converted to a string.
Note that there is no space between% and =

2.2 Claim identification
A declaration identifies a variable or method that is used to define a global in a JSP page. Variables and methods defined by the identity can be accessed by the entire JSP page.
<%! Declares the code for a variable or method%>

2.3 Code Snippets
The so-called code snippet is the Java code or script code embedded in the JSP page. The code snippet will be executed during the processing of the page request, with Java code defining the variable or process Control statement lights, and scripting code to apply the JSP's built-in object to the page output, process requests and responses, access session sessions, and so on.
<%java code or script code%>


3 JSP Action ID

3.1 Include file ID <jsp:include>

Used to include other files in the current page.

<jsp:include page= "url" flush= "False|true" >
Child Action ID <jsp:param>
</jsp:include>

3.2 Request Forwarding Identity <jsp:forward>

You can forward requests to other Web resources, such as another JSP page, an HTML page, and a servlet light. After the request is forwarded, the current page is no longer executed and the target page specified by the identity is lost.

Java Web Development--jsp Basic Grammar essays

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.