JSP Basic Grammar of Learning Notes

  • 2021-07-22 10:58:33
  • OfStack

jsp page element composition

jsp page components are: directives, comments, static content, expressions, small scripts, declarations.

jsp instruction

page Directive: Usually located at the top of the jsp page, you can have multiple page directives on the same page

include instruction: Embed an external file into the current jsp file and parse the jsp statement in this page at the same time

taglib Directive: Define a new custom tag using the tag library and initiate the custom behavior in 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 Notes

Comments on the jsp page.

Notes for HTML:

< ! --html Notes-- > //Visible to the client

Notes for jsp:

< %--html annotations--% > //Client not visible

jsp script comments:

//Single line comment

/**/Multiline comment

jsp script

java code executed in the jsp page

Syntax:

< % java code% >

jsp Declaration

Define variables or methods on the jsp page

Syntax:

< %! java code% >

jsp expression

Expressions executed in jsp pages

Syntax:

< % = Expression% > //Note: Expressions do not end with semicolons

Life Cycle of jsp Pages

The life cycle of JSP is divided into four main stages, which are very similar to the life cycle of Servlet, and have the following points:

JSP compilation:

When a browser requests an JSP, the JSP engine first checks whether it needs to compile the page. If the page has never been compiled, or if JSP has been modified because it was the last page compiled by the JSP engine.

The compilation process consists of three steps:

Analyze JSP.
Open JSP to servlet.
· Compile this servlet.

JSP initialization:

The jspInit () method is invoked before a container loads an JSP for any of its service requests. If you need to perform JSP-specific initialization

JSP executes:

This phase of the life cycle of the JSP represents all interactions requested until the JSP is broken.

When the browser requests an JSP and the page has been loaded and initialized, the JSP engine calls the _ jspService () method in JSP.

JSP Cleanup:

The lifecycle destruction phase of JSP represents the container used when JSP is removed.

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


Related articles: