Jsp
by HTML and Java statements are stitched together with a suffix called . JSP
1, Jsp translated into servlet: First translation,Tomcat will translate the files placed in the installation directory (all Jsp The page is essentially a Servlet program)
2. Compile to byte code
(in JSP life cycle, translation and compilation only one time)
3. class loading --web container loading the newly generated servlet class
4. Create A Servlet instance
5, Jspinit ()
6, _jspserver ()
7, Jspdestory ()
underlying type: cannot be inherited (final)
Pageeconding: The type of storage to get
JSP simplifies creating servlets that produce text
JSP Web pages are primarily composed of elements and template data
1, the template data is The static part of the JSP
2.WEB container does not handle
3, elements must be interpreted through the WEB container
4, the elements are based on the syntax of XML , and the same case
Web container supports two different formats of JSP Syntax
1. Normal format and XML compatible format
2, the common JSP syntax is designed for developers to use
3,XML - compatible JSP syntax is designed to be used easily by development tools
script elements, embedded between template data blocks JAVA Code
1. declaration <% declaration %>
2, Scriptlet <% code %>
3. script expression <% script expression %>
Scriptlet inserting Java Code snippets directly into the template data
a Scriptlet can only be a Java program
must meet Specifications for Java
start with "<%" and End With"%>" to include the program code snippet
<%java Program code %>
Guide Pack:<% @page ="com.lovo.user"%>
JSP Built-in objects : For example: Print out , session , etc.
Out.print () = <%=%> simultaneous printing
Declaring variables:
1, <%! can have variables and methods %> Global Variables must end with a semicolon
2. <% declare variable %> local variable
JSP comment <%----%>
HTML Comments <!----> the Source code on the page will be displayed
Java Comments / * *
JSP directives
1.Page: entire page
2.Include: The text in the text is statically contained in the past <%@ include file=""%>
<jsp:directive.include file= "" ></jsp:include>
dynamic inclusion (each containing will generate a JSP)
<jsp:forward page= "" ></jsp:forward> Jump to another page
3.Taglib
Application: Global Variables
PageContext: pagecontext object for the current page
The JAVA Web development model
script elements:<%%>
directive:<%@%> page include public
Standard action:<jsp:page = "" >
Mode:
Jsp+javabean
<jsp:userbean id = "Beanname" variable name scope= "Page|request|session|application" >
<jsp:userbean id= "Stu" class= "com.my.bean.Student" scope= "Request"/>
<jsp:setproperty property= "id" name= "stu" param= "userid"/>
<jsp:getproperty property= "id" name= "stu"/>
MVC Model
1.define a series of beans to represent the data
2.use a Servlet to process requests
3. populating the Bean in the Servlet
4. Ina servlet , store the Bean in a request, session, or servlet Context
5. Forward the request to the JSP page
6. In the JSP page, extract the data from the Bean
EL Expression
${ expression }--with an object . Properties
Printed data:1,<%=%>
2,out.print ();
3,${ object . Properties }
EL 's Implicit object:ten species
The EL operator is divided into four types:
1. Properties and collection access operators
2, arithmetic operator ${person.age + ten} get age (+-*/)
3, relational operator ${person.age>20} determine whether the age equals (= =)
4. Logical operator (| | , &&)
EL function
JSP standard Tag library JSTL
Core Library (CORE)
Prefix: prefix URL: address
Example:<% @taglib prefix= "C" url= "Http://java.sun.com/jsp/jstl/core"%>
JSTL Process Control
<c:if test= "${person.age>20}" >
older than 20
</c:if>
If/else
<c:choose>
<c:when test= "${person.age>20}" >
He's older than 20.
</c:when>
<c:when test= "${person.age==20}" >
his age equals 20.
</c:when>
<c:otherwise>
his age is less than 20.
</c:otherwise>
</c:choose>
Cycle
Step: how often to start printing
Items: Looping collection
list<string> list = new arraylist<string> ();
List.add ("Qwe");
List.add ("Qee");
List.add ("wet");
Request.setattribute ("myList", list);
Varstatus: The format of the variable
<c:foreach var= "I" begin= "1" end= "Ten" step= "2" items= "${mylist}" varstatus= "STA" >
Sta.index: subscript
Sta.count: The first few times to print
${i}===${sta.index}====${sta.count}=====${sta.first}=====${sta.last}
</c:forEach>
JSP JSP directives