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