JSP Basic Syntax

Source: Internet
Author: User

1. Introduction of JSP

Meaning: is running on the server side of the Java page, is a dynamic web technology, the development of the use of HTML nested Java code to implement the way

What is the process of JSP execution?

Translation phase: When the Web server receives a JSP request, it translates the JSP file into a. java file

Compile stage: Compile the. java file into a. class file

Execution phase: Executes a bytecode file that has been compiled. Return the generated results page to the client display

2. Composition of script elements

(1) Small script

<%
Java statements
%>
The contents of the small script will be translated into the code within the _jspservice () method

Can contain:
1. Local variable declaration
2. Process Control Structure

Cannot contain:
1. Method definitions
2. Declaring global variables (using public, private, and so on)

(2) expression

<%= variable name, calculation%>
The contents of the expression are translated into the parameters of the Out.print () method
Can contain:
1. Variable name (output variable value)
2. Formula (output calculation result)
3. Method invocation (output return value)
not to end with;

     <% //can write         String str= "goodbye!" separately ;           for (int i=1;i<=10;i++) {     %>                   }in Java%>

(3) statement

<%!
Method definition
Global variables
%>
The code inside the Declaration block is translated into methods and global variable declarations in the Java class
Cannot contain Process Control structure

(4) Static content

Static content is translated into the out.write () output statement

El expression

<jsp:include> page contains dynamic include and <% @include%> static include------> Resolve Code Redundancy

A, static contains:

<% @include file= "URL"%>

jsp+html pages can contain

In work, the Jsp-->java translation phase, just merge several page source code together, run efficiently, compile into the same Java object and merge directly in Java

Cons: When there is a small script, there will be a duplicate variable declaration, 500 error, JSP cannot appear duplicate variable declaration, string path; string BasePath

b, dynamic inclusion: the use of multiple

<jsp:include page="URL">

Embed several page-generated content into that location at run time, and write small scripts that can declare the same variables

JSP Basic Syntax

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.