Chapter two first knowledge of JSP

Source: Internet
Author: User

The second chapter first knowledge JSP one. JSP Brief Introduction 1, is JSP

JSP refers to the HTML embedded in Java scripting language. Full Name (Java Server Pages)

When a user accesses a web app through a browser, the JSP container is used to process and run the requested JSP, and the resulting page is returned to the client browser for display.

Tomcat server belongs to JSP one of the containers.

2, the Origin of JSP

JSP is by Sun company advocacy, many companies to participate in the establishment of a dynamic Web technology standards.

and has the advantages of cross-platform, easy to maintain, easy to manage.

3. Part of JSP

JSP pages consist of elements such as static content, directives, expressions, small scripts, declarations, standard actions, annotations , and so on.

Two JSP element 1. Static content

Static content is static text in a JSP page, which is basically HTML text, independent of Java and JSP syntax.

2. JSP directive element

The role of the JSP directive element is to control certain features of the JSP page when the JSP is running, by setting properties in the directive.

Syntax: <%@ Property 1= " property Value "... .. Property n= " property value "%>

Page Common properties of Directives

Property

Describe

Language

Specify JSP script language used by the page, default to "Java"

Import

Referencing the class file used in the scripting language by property

ContentType

used to specify MIME Types and JSPs The character encoding format in which the page responds with the default "Text/html;charset=iso-8859-1"

3. JSP expressions

An expression is a representation of the data that the system calculates and displays as a value.

syntax: <% =java variable or expression%>

Cases:

<%= Math.max (grade[0],grade[1])%>

<% Out.print (Math.min (grade[0],grade[1)); %>

4. JSP Small Script

The small script can contain any Java fragments, the form is more flexible, by writing in a JSP page can be complex operations and business processing.

The method is written by the Java program fragment insertion <%%> tag.

syntax: <% java Fragment Code .....%>

Cases:

<%

Int[] grade={70,80,90};//An array of student scores

%>

5. The declaration of the JSP

When you write a JSP page program, you sometimes need to define member variables and methods for your Java script, which you need to implement with a JSP declaration.

Syntax: <%! Statement Content ....%>

Example: How to format display time

<%!

String FormatDate (Date d) {

Java.text.SimpleDateFormat formater=

New Java.text.SimpleDateFormat ("yyyy mm month DD day hh" mm min ss sec ");

return Formater.format (d);

}

%>

6. Comments in the JSP

Single-line comment: <%// single-line comment%>

Multiline Comment: <%/* Multiline Comment */%>

in the JSP page, the small script (scriptlet) , expressions (expression) , Declaration (Declaration) collectively referred to as JSP The script element.

Three    JSP principle 1. Translation phase

When the Web container receives the JSP request, the JSP file is translated first, and the compiled JSP file is converted into the recognizable Java source code through the JSP container.

2. Compile Stage

Compile the Java source file into an executable bytecode file.

3. Implementation phase

Executes a binary bytecode file that returns the resulting page of results to the client browser display.

Web The container will save the compiled bytecode file in memory, when the customer requests the same JSP again , you can reuse this compiled bytecode file without recompiling the same JSP file.

So the first time the JSP request is slow, the subsequent speed will be very fast.

Chapter two first knowledge of JSP

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.