JSP elements and tags

Source: Internet
Author: User
Tags html comment
1 JSP running principle when a JSP page on the server is requested for execution for the first time, the JSP engine on the server first translates the JSP page file into a java file, compile the java file to generate a bytecode file, and then respond to the customer's request by executing the bytecode file.

1. How JSP works
When a JSP page on the server is requested for execution for the first time, the JSP engine on the server first translates the JSP page file into a java file, and then converts the java File
Compile and generate a bytecode file, and then respond to the customer's request by executing the bytecode file. When the JSP page is requested again, the JSP Engine will directly execute this bytecode file to respond to the customer.
The main work of bytecode files is:
(1) Submit the common HTML Tag (static part of the page) on the JSP page to the client's browser for display.
(2) execute the java program (dynamic part of the JSP page) between "<%" and "%>" and hand the execution result to the client's browser for display.
(3) When multiple customers request a JSP page, the JSP Engine Starts a thread for each customer instead of a process,
2. a JSP page can be composed of five elements:
(1) Common HTML tags.
(2) JSP tags: such as command tags and action tags.
(3) Declaration of variables and methods.
In "<% !" And "%>" between the markup symbols declare variables and Methods
In "<% !" Variables declared between and "%>" are valid throughout the JSP page. "<% !" The variables declared between and "%>" are valid throughout the JSP page, because
When the JSP Engine translates JSP pages into Java files, these variables are used as member variables of the class.
In "<% !" And "%>". This method is valid throughout the JSP page.
(4) Java program.
Insert a Java program film between '<%' and '%>. When the JSP Engine translates JSP pages into Java files, the variables of each program piece are used as
Variable, that is, local variable.
(5) Java expressions.
Insert an expression between "<% =" and "%>" (Note: The statement cannot be inserted. "<% =" is a complete symbol, "<%" and "=" do not have spaces)
3. Comment in JSP
(1) HTML comment: Mark the symbol" Add comments
(2) JSP comments: add comments between the markup symbol "<% --" and "-- %>"
4. JSP command label
1. The page command is used to define some attributes of the entire JSP page and the values of these attributes.
Page command format:
<% @ Page attribute 1 = "value of attribute 1" attribute 2 = "value of attribute 2 "...... %>
Attribute values are always enclosed by single or double quotation marks.
<% @ Page contentType = "text/html; charset = GB2312" %>
1. language attributes
Defines the scripting language used by the JSP page. Currently, the attribute value can only be "java"
<% @ Page language = "java" %>
The default value of the language attribute is "java", even if you do not use the page command to specify the value of this attribute on the JSP page
2. import attributes
This attribute is used to introduce classes in the Java core package to the JSP page, so that packages can be used in the program, variable, function declaration, and expression sections of the JSP page.
. You can specify multiple values for this attribute. The value of this attribute can be all classes in a Java package or a specific class.
3. contentType attributes
Defines the MIME (Multipurpose Internet Mail Extention) Type of JSP page response and the encoding of JSP page characters
<% @ Page contentType = "text/html; charset = GB2312" %>
4. session attributes
Used to set whether to use a built-in session object.
The value of the session attribute can be true or false, and the default value of the session attribute is true.
5. buffer attributes
The built-in output stream object out is used to send certain information or running results of the server to the client for display. The buffer attribute is used to specify the size of the buffer set for the out or not to use the buffer.
The buffer attribute can be set to "none" and the buffer is not used when the buffer is set to out. The default value of the Buffer attribute is 8 KB.
<% @ Page buffer = "24kb" %>
6. auotFlush attributes
Whether the buffer is automatically refreshed when the buffer of the specified out is filled up
AuotFlush can be set to true or false. The default value of the auotFlush attribute is true. When the auotFlush attribute is set to false, if the out buffer is filled up
Cache overflow exception. When the buffer value is "none", the auotFlush value cannot be set to false.
7. isThreadSafe attributes
Used to set whether JSP pages can be accessed through multiple threads.
Set the value of isThreadSafe to true or false. When the value of isThreadSafe is set to true, the JSP page can respond to requests from multiple customers at the same time. When isThreadSafe is
When the property value is set to false, the JSP page can only respond to one customer's request at the same time. Other customers need to wait in queue. The default value of the isThreadSafe attribute is true.
8. info attributes
This attribute prepares a string for the JSP page. The attribute value is a string.
<% @ Page info = "we are students" %>
You can use getServletInfo () on the JSP page to obtain the property value of the info attribute.
Note: The page command can only specify multiple values for the import attribute. Only one value can be specified for other attributes.
2. include command labels
Format:
<% @ Include file = "file name" %>
Purpose:
Is to insert a static file at the location where the command appears on the JSP page. The inserted file must be accessible and usable.
The current JSP page is in the same Web service directory. Static insertion means that the current JSP page and the inserted part are merged into a new JSP page, and then the JSP Engine
The new JSP page is converted into a Java class file. Therefore, after the file is inserted, make sure that the newly merged JSP page complies with the JSP syntax rules, that is, it can become a JSP page file.

5. JSP action tag
Action tags are special tags that affect the functions of JSP runtime.
1. include action labels
Format:
Or
This action tag tells the JSP page to dynamically include a file, that is, the file is added only when the JSP page is running. Unlike the include command label of a static insert file
When converting a JSP page into a Java file, notify Java
Interpreter. This file is included in the JSP Runtime (the bytecode file of the Java file is loaded and executed. If the file is a common text file, the file content will be sent
The client is responsible for displaying the files sent to the client. If the files contained are jsp files, the JSP Engine executes the files and sends the execution results to the client. The client is responsible for displaying the results.
2. param action label
The param TAG provides additional information for other tags in the form of a "name-value" pair. This tag is used with jsp: include, jsp: forward, and jsp: plugin labels.
Param action label:

When this label is used together with the jsp: include label, you can pass the value in the param label to the file to be loaded by the include command. Therefore, if
Combined with the param tag, you can provide information to the file during file loading.



3. forward action tag
Forwar command:
Or
The role is to stop the execution of the current page from this command and switch to another JSP page.
This command can also be combined with the param command to send information to the page to be transferred.



4. plugin action tag
Use common HTML tags on the pageAllows customers to download and run a small java applet application, but not all customers' browsers
Java apple applets are supported. Using the plugin action tag ensures that customers can execute your small applications.
The action tag indicates that the JSP page is loaded with java plugin, Which is downloaded by the customer and used to run the Java applet.
Plugin action Tag:


Tip: it indicates whether the browser supports plug-in download.


5. useBean action tag
This label is a very important action label to create and use a java beans.

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.