Basic elements of a JSP page

Source: Internet
Author: User

JSP page elements consist of: static content, directives, expressions, small scripts, declarations, annotations.

JSP directives include:

Page directive: Usually 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 statements in the page.

Taglib directives: Use the tag library to define new custom tags and enable custom behaviors in JSP pages.

Page instruction Syntax:

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

Property

Describe

Default value

Language

Develop the scripting language used by JSP pages

Java

Import

Use this property to refer to the class file used in the scripting language

No

ContentType

Used to specify the encoding used by the JSP page

Text/html

Iso-8859-1

ContentType is generally set to contenttype= "text/html; Charset=utf-8 "

JSP Notes

Comments on the JSP page. There are several ways:

Comments for HTML: (client visible)

<!--HTML comments--

Comments for JSP: (Client not visible)

<%--HTML Comment--%>

JSP script comments: (can be embedded in the comments of the JSP)

Single-line Comment

/* Multiline Comment */

JSP Script

The Java code that executes in the JSP page.

Grammar:

<% Java Code%>

Example:

<%

Out.println ("moonlit");

%>

JSP Statement

Define variables or methods in the JSP page.

Grammar:

<%! Java Code%>

Example:

<%!

String s = "moonlit"; A string variable was declared

int add (int x, int y) {//declares a function that returns an integral type, which implements the summation of two functions.

return x + y;

}

%>

After declaring the variables and functions, we can use the variables and functions in the next step.

JSP An expression

An expression that executes in a JSP page.

Grammar:

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

Example: (e.g. display JSP life defined s in JSP page)

<p> Name: <%=s%></p>

Basic elements of a JSP page

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.