Chapter 1 Basic JSP syntax and chapter 1 jsp syntax

Source: Internet
Author: User
Tags html comment

Chapter 1 Basic JSP syntax and chapter 1 jsp syntax
Jsp page element structure

The jsp page consists of commands, comments, static content, expressions, small scripts, and declarations.

Jsp commands

Page command: Usually located at the top of the jsp page. The same page can have multiple page commands.

Include command: embed an external file into the current jsp file and parse the jsp statement on this page

Taglib command: Use the tag library to define a new custom tag and start the custom behavior on the jsp page.

Page instruction syntax

<% @ Page attribute 1 = "attribute value" attribute 2 = "attribute value 1, attribute value 2" attribute n = "attribute value n" %>

Jsp comments

Comment on the jsp page.

HTML comment:

<! -- Html annotation --> // visible to the client

Jsp comments:

<% -- Html comment -- %> // invisible to the client

Jsp script annotation:

// Single line comment

/**/Multi-line comment

Jsp script

Java code executed on the jsp page

Syntax:

<% Java code %>

Jsp Declaration

Define variables or methods on the jsp page

Syntax:

<%! Java code %>

Jsp expressions

Expressions executed on the jsp page

Syntax:

<% = Expression %> // Note: The expression does not end with a semicolon

Lifecycle of a jsp page

The lifecycle of JSP is divided into four major stages, which are very similar to those of Servlet. The following are some key points:

JSP Compilation:

When the browser requests a JSP, the JSP Engine first checks whether it needs to compile the page. If the page has never been compiled, or if the JSP has been modified, it is the last page for compiling the JSP Engine.

The compilation process consists of three steps:

  • Parse JSP.

  • Open JSP into servlet.

  • Compile this servlet.

JSP initialization:

Call the jspInit () method before a container loads any service request of a JSP. If you need to perform JSP-specific Initialization

JSP execution:

This stage of the JSP lifecycle represents all the interactions of the request until the JSP is destroyed.

When the browser requests that a JSP and page have been loaded and initialized, the JSP Engine calls the _ jspService () method in JSP.

JSP cleanup:

The JSP lifecycle destruction stage indicates that the container used when the JSP is deleted.

The jspDestroy () method is equivalent to the destroy method of JSP servlet. Override jspDestroy when you need to perform any cleanup, such as releasing the database connection or closing open files.

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.