Javaweb Study summary third--into the JSP page element

Source: Internet
Author: User
Tags html comment

Javaweb Learning (III.)-into the JSP page element

JSP: Java Server Pages, translated as Java Servers page. Its script, in the Java language, inherits all the benefits of Java. JSP elements can be divided into three types of instruction elements, script elements, and action elements. The instruction element is designed for the JSP engine, which controls how the JSP engine handles the code, the script element is the Java code embedded in the JSP page, and the action element is responsible for connecting the components used. Below, I briefly summarize the commonly used instruction elements and attributes.

one: JSP directive element

JSP instruction elements are mainly used to communicate with the JSP engine, providing information about the whole JSP Web page, and to set the relevant properties of the JSP page. In short, JSP is mainly used to implement some pre-defined functions, like the macro definition in C + + define. The relevant form of the directive element is as follows:

The following three types are mainly included in the JSP directive element: Page, include, and taglib directives.

1.1 page directive

The page directive is used to define the global properties in the JSP and describes the instructions related to pages. In a JSP page, the page directive can appear multiple times, but each property can only appear once, and the repeating property setting overrides the previous setting. Page has 13 properties:

Language= "Java": indicates that the syntax of the script conforms to the Java syntax specification

Extends= "ClassName": Specifies the class to use when compiling JSP pages

Import= "Required Classes": Import the required classes, the same as Java, if you need to import more than one class, you can use, separate the various classes;

Session= "True|false": Specifies whether to use HTTP Session. The default is true, which means use;

Buffer= "NONE|8KB|SIZEKB": Specifies the user JSP page for the output of the browser, the default value is None, the buffer is not used;

Autoflush= "True|false": For buffer overflow, if true, the output is normal, if false, overflow will error;

Isthreadsafe= "True|false": Sets whether the JSP page can be used multi-threaded, the default value is true;

info= "text": Text is added to the JSP in the execution, using the Servlet.getservletinof method to remove;

Errorpage= "Relative path": Sets the processing JSP file for exception events;

Iserrorpage= "True|false": Sets whether this page is an error handling page with a default value of false;

Contenttype= ' text/html '; Charset= "Utf-8": MimeType: Specifies the content type that returns the browser, with 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 the encoding format for the Settings page: Common UTF-8,GB2312,GBK, etc.

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

Iselignored= ' True|false ': Indicates whether an EL expression is executed or ignored in a JSP web page

Two: JSP scripting elements

The script element contains the three main elements of expressions, scripts, and declarations.

2.1 Declaration: A JSP declaration is used to define one or more variables or methods and classes, and the declaration will not have any output, which is generally used in conjunction with scripting.

2.2 Expression: The JSP expression is used to output Java data directly on the Web page. All expressions, whether complex or simple, are computed as a single result or value, and the JSP page relies on the JspWriter object output JSP expression, which can accept any Java expression result, convert it to a string type, and then output it to the response buffer.

2.3 Script: If you need to use Java to achieve more complex operations and control, then the declaration will not meet the requirements, at this time we apply to the script implementation.

Three: JSP action elements

The JSP action uses markup in the XML syntax format to control the behavior of the servlet engine. JSP actions can be used to dynamically insert files, reuse JavaBean components, redirect users to additional pages, and generate HTML code for Java plugins. The basic JSP actions include the following:

Jsp:include introduce a file when the page is requested

Jsp:usebean Find or instantiate a JavaBean

Jsp:setproperty Setting properties for JavaBean

Jsp:getproperty output the properties of a JavaBean

Jsp:forward to move the request to a new page

Jsp:plugin generates an object or embed tag for the Java plug-in based on the browser type.

the difference between an action element include and forward in a JSP : the include directive is used to include the contents of another file in a JSP page, and the containing process is static; forward is a guide, that is, a jump, Once the forward is executed, it jumps to another file.

Four: JSP annotations

JSP comments are generally divided into two types: the JSP itself is used to describe the JSP program code, it will be ignored by the JSP container, and not appear in the Web page source code, this kind of comment is called JSP comments, and the other is HTML, used to describe the JSP page after the execution of the results, this gaze will be seen by the client user.

The syntax of the HTML comment is as follows:

The syntax for JSP annotations is as follows:

Because the scripting code in the JSP page uses the Java language, it is also possible to use the Java annotation mechanism, i.e.//or/*/.

Javaweb Study summary third--into the JSP page element

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.