JSP Learning notes of the basic grammar _jsp programming

Source: Internet
Author: User

JSP page Element composition

JSP page components are: Directives, comments, static content, expressions, small script, declaration.

JSP directives

Page instruction: typically at the top of a JSP page, the same page can have multiple page directives

Include directive: Embed an external file into the current JSP file and parse the JSP statement in the page

TAGLIB directive: Use tag Library to define new custom label, start custom behavior in JSP page

Page instruction Syntax

<% @page Property 1 = "Property Value" Property 2 = "Property value 1, property value 2" Property n= "Property value N"%>

JSP comments

Comments on the JSP page.

Comments for HTML:

<!--HTML annotation-->//client visible

Comments for JSP:

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

JSP script annotations:

Single-line Comment

/**/Multiple Line comments

JSP scripts

Java code executed in a JSP page

Grammar:

<%java Code%>

JSP declaration

Define a variable or method in a JSP page

Grammar:

<%!java Code%>

JSP expression

Expressions executed in a JSP page

Grammar:

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

Life cycle of JSP pages

The lifecycle of the JSP is divided into four major phases that are very similar to the servlet lifecycle and have the following points:

JSP Compilation:

When the browser requests a jsp,jsp engine first check if it needs to compile the page. If the page has never been compiled, or if the JSP has been modified because it is the last page compiled by 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 a JSP for any of its service requests. If you need to perform JSP-specific initialization

JSP Execution:

This phase of the JSP's lifecycle represents all of the requested interactions until the JSP is corrupted.

When the browser requests a JSP and the page has been loaded and initialized, the JSP engine invokes the _jspservice () method in the JSP.

JSP cleanup:

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

The

Jspdestroy () method is the Destroy method for the equivalent JSP servlet. Overwrite Jspdestroy when you need to perform any cleanup, such as releasing the database connection or closing the open file.

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.