Java Web Learning summary Article 3-elements of JSP pages and Java Web Article 3

Source: Internet
Author: User
Tags html comment

Java Web Learning summary Article 3-elements of JSP pages and Java Web Article 3

Java Web Learning (III)-elements of JSP pages

 

JSP: Java Server Pages, translated as a Java Server Page. The script adopts the Java language and inherits all the advantages of Java. JSP elements can be divided into three types: command elements, script elements, and Action elements. The instruction element is designed for the JSP engine. It controls how the JSP Engine processes code. The script element is the Java code embedded into the JSP page, and the Action element is used to connect the components used. Below, I will briefly summarize the commonly used command elements and attributes.

I. JSP instruction Elements

JSP command elements are mainly used to communicate with the JSP Engine, provide information related to the entire JSP page, and set attributes related to the JSP page. To put it simply, JSP is mainly used to implement some predefined functions, like the macro definition define in C ++. The command element is in the following format:

JSP command elements mainly include the following three types: Page, include, and taglib commands.

1.1 page command

The page command defines the global attributes in JSP and describes the page-related instructions. In a JSP page, the page command can appear multiple times but only once for each attribute. Repeated attribute settings will overwrite the previous settings. Page has 13 attributes:

Language = "java": indicates that the script syntax complies with java syntax specifications.

Extends = "className": Specifies the class used to compile the JSP page.

Import = "Required class": the class required for import, which is the same as java. If you need to import multiple classes, you can use them to separate the classes;

Session = "true | false": Specifies whether to use HTTP Session. The default value is true;

Buffer = "none | 8kb | sizekb": Specifies the browser output of the user's JSP page. The default value is none, and no buffer is used;

AutoFlush = "true | false": When buffer overflow occurs, if it is true, the output is normal. If it is false, an error is returned;

IsThreadSafe = "true | false": sets whether JSP pages can be used in multiple threads. The default value is true;

Info = "text": Add the text to JSP word upon execution, and retrieve it using Servlet. getServletInof;

ErrorPage = "relative path": sets the JSP file for handling exception events;

IsErrorPage = "true | false": sets whether the page is an error handling page. The default value is false;

ContentType = ''text/html ''; charset =" UTF-8 ": mimeType: specifies the content type of the returned browser, which has the following property values:

Text/plain (plain text page), text/html (plain text HTML), text/xml (xml interface), application/x-msexcel (Excel file) and application/x-msword (Word file );

Charset is used to set the page encoding format: Commonly Used UTF-8, gb2312, gbk, and so on

PageEncoding = ''utf-8 '': Specifies the character encoding of the JSP page.

IsELIgnored = ''true | false'': Indicates whether to execute or ignore the EL expression in the JSP webpage.

Ii. JSP script elements

Script elements include expressions, scripts, and declarations.

2.1 Declaration: the JSP declaration is used to define one or more variables, methods, and classes. The declaration does not have any output. It is generally used in combination with scripts.

2.2 Expression: JSP expression is used to directly output Java data to a webpage. All expressions, whether complex or simple, are computed into a separate result or value. The JSP page depends on the JSPWriter object to output the JSP expression. This object can accept any Java expression result, convert it to the String type and then output it to the response buffer.

2.3 Script: If you need to use Java to implement more complex operations and control, the declaration cannot meet the requirements. At this time, we use the script for implementation.

Iii. JSP action elements

JSP actions use tags in XML syntax to control the behavior of the Servlet engine. JSP actions can be used to dynamically Insert Files, reuse the JavaBean Component, redirect users to another page, and generate HTML code for the Java Plug-in. JSP basic actions include the following:

Jsp: include introduces a file when the page is requested

Jsp: useBean: Find or instantiate a JavaBean

Jsp: setProperty: Set attributes of JavaBean

Jsp: getProperty outputs the attributes of a JavaBean.

Jsp: forward transfers requests to a new page

Jsp: plugin generates the OBJECT or EMBED tag for the java Plug-in based on the browser type.

The difference between action elements include and forward in JSP: The include command is used to include the content of another file on the JSP page, and the inclusion process is static; the forward is oriented, that is, jump, after the forward Command is executed, the system jumps to another file.

Iv. JSP comments

JSP comments are generally divided into two types: one is that JSP is used to describe the JSP program code, which will be ignored by the JSP Container and will not appear in the source code of the web page, this annotation is called JSP annotation, and HTML is used to describe the result of JSP page execution. This kind of annotation will be seen by client users.

The syntax of HTML comment is as follows:

The syntax of JSP annotations is as follows:

Because the script code on the JSP page uses the Java language, you can also use the Java annotation mechanism, that is, // or /**/.

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.