jsp--Getting Started

Source: Internet
Author: User
Tags tomcat server

The full name of the JSP is Java Server Pages, the Chinese name Java Servers page, which is simply a simplified servlet design, it [1] is advocated by Sun Microsystems Company, many companies involved in the establishment of a dynamic Web technology standards. JSP technology is a bit like ASP technology, it is in the traditional Web page HTML (standard Common Markup Language subset) file (*.htm,*.html) inserted Java program segment (scriptlet) and JSP tag (tag), thereby forming a JSP file, suffix named (*.jsp). Web applications developed with JSP are cross-platform and can run on Linux and other operating systems.

Features of JSP:

1) The operation of the JSP must be given to the Tomcat server.

2) JSP pages can either write HTML code or write Java code.

The execution process of the JSP:

1) Browser Access xxx.jsp page, tomcat scan to xxx.jsp file, in%tomcat%/work to translate JSP file into Java source file.

2) The Tomcat server translates the JSP Java source file into a class byte-code file.

3) The Tomcat server constructs an object for the JSP class.

4) The Tomcat server invokes the method in the JSP class, and the returned content is displayed in the browser.

Attention:

1) The first time to visit the JSP to perform the above four steps, the nth access to only execute (4).

2) If the JSP file modification or JSP temporary files are deleted, when accessing the JSP page, will go back to the above 4 steps.

3) The JSP-translated class is a servlet class that can be viewed through the translated Java source files.

The syntax of the JSP:

1) JSP templates: HTML code in JSP pages with HTML statements when creating JSP pages with Eclipse code as follows

1 <%@ Page Language="Java"ContentType="text/html; Charset=utf-8"2 pageencoding="UTF-8"%>3 <!DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://www.w3.org/TR/html4/loose.dtd ">4 <HTML>5 <Head>6 <Metahttp-equiv= "Content-type"content= "text/html; charset=utf-8">7 <title>Insert Title here</title>8 </Head>9 <Body>Ten  One </Body> A </HTML>

2) JSP expression

Syntax: <%= variable or expression%>

Effect: The value of the output variable to the browser or the result of the expression being evaluated.

Attention:

1) The principle of the expression is translated into Out.print ("variable"), through the method to write content to the browser.

2) There is no need to end a semicolon after the expression.

3) JSP script

Syntax: <%java code%>

Role: Executing Java code

Note: The rationale is to copy the Java code in the script intact into the _jspservice method.

4) JSP Declaration

Syntax: <%! Variable or method%>

Function: A variable or method that declares a JSP.

Note: variable sinks are translated into member variables, and methods are translated into member methods.

5) JSP Comments:

Syntax: <%--JSP comment--%>

Function: Comment The JSP code.

Note: Comments from the HTML code are translated into the JSP Java source file by Tomcat, and the comments of the JSP cannot be translated and executed.

JSP three major instructions

1) Page directive

1 <%@ Page Language="Java" 2 ContentType="text/html; Charset=utf-8"3 pageencoding="UTF-8"4 Import="java.util.*"5 ErrorPage="error.jsp"6 Iserrorpage="false"7 Buffer="8kb"8 Session="true"9 iselignored="false"Ten      One     %>

Explanation: Language--tells the server what dynamic language to use to translate JSP files.

ContentType-the data type and content encoding format that the server sends to the browser.

Pageencoding--tells the server what encoding format to use to translate the JSP file.

Import--tells the server Java file which package to use, and separates multiple packages with commas.

ERRORPAG--The page that jumps when a JSP page error is set.

Iserrorpage-The value has a true and false two. The true identity translates into a Java file that has a exception object, False No.

Buffer--Sets the cache size of the out output object in the page, which defaults to 8KB, and is recommended to use multiples of 8.

Iselignored-The value has true and false two, setting whether the page ignores El expressions.

2) include directive: static inclusion

1 <% @include File = " common/header.jsp " %>

Role: Include additional pages in the current JSP page.

Note: The principle is to translate the contents of the included pages into the included pages, and merge them into a Java source file and run the compilation. With static inclusions, the global HTML tags (html, head, and body) are not required to appear in the included page.

3) taglib Directive: Import Tag Library

<% @ taglib URI = " File Location " prefix = " prefix name " %>

Role: Import the JSP tag library.

      

jsp--Getting Started

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.