A. JSP
principle: JSP is actually a servlet.
Servlet responsible for business logic processing, JSP is only responsible for display. In development, there cannot be a single line of Java code in the JSP
Two JSP Syntax
1. jsp template elements: HTML tags and text in JSP
2. Script: Write Java code, <%%>
3. expression: For output variables and expressions, <%=%>
4. Note: Divided into three types
a) <!----> : The JSP will be translated when translated into a servlet. Also available on the page.
b) <%/*.......*/%>: The JSP is translated when translated into a servlet, but not in the page (right-click Source code).
c) <%--..........--%>: The JSP will not be translated when translated into a servlet.
three. Instruction
1. page: This command can be placed anywhere in the JSP page. Scoped to the entire JSP page
Property:
language : Java is the default value, and currently only Java
extends : The parent class of the servlet corresponding to the JSP
Import : Imports The packages, classes used in this JSP page. Multiple packages are separated by commas, and the default imported packages are: java.lang.*,javax.servlet.*,javax.servlet.http.*,javax.servlet.jsp.*
Session : Whether to create a HttpSession object, which is true by default
Buffer : Set cache, Value none|8kb|sizekb, default 8kb. is typically the default value.
AutoFlush : Auto Refresh, True|false, default true.
IsThreadSafe : whether the servlet corresponding to the JSP implements the Singletreadmode interface. The default is true, False is implementation. Implementing a single Thread
ErrorPage : Set error page
Configuring the default error page in Web. XML
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/exce.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.jsp</location>
</error-page>
Iserrorpage : The default is Flase, which indicates whether to generate reference exception for Throwable objects.
ContentType : Sets the encoding of MIME types in HTML, as Response.setcontenttype () in the servlet;
pageencoding : tells the engine which encoding to use when translating JSPs.
isellgnored : If the El expression is ignored , JSP2.0, the default is False
Four. include:
Contains:
1. Dynamic Inclusion
<jsp:include page= "...."/>
If there are two JSP files, a. A dynamic contains B,a and B are translated into A_jsp.class and B_jsp.class files respectively, then the container merges two servlets. Output again.
2. static inclusions
<%@ include file= "..."%>
A and B translated into a a_jsp.class file. have been merged and given to the container. Output again.
2. taglib:
<% taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
Five. Nine large implicit objects
Request:httpservletrequest
Response:httpservletrequest
session:httpsession ( only if the session is set to true in the page directive)
Config:servletconfig
Application:servletcontext
exception:throwable ( only if Iserrorpage is set to true in the page directive)
page: References to the current servlet
Out:jspwriter (equivalent to PrintWriter)
PageContext:javax.servlet.jsp.PageContext;
Role:
A. you can get the other 8 large implicit objects
B. itself is also a domain object, scoped to this page
provides methods for manipulating other domain objects (servletcontext,httpsession, ServletRequest)
To manipulate the own domain object:
Pagecontext.getattribute (Stringname);
Pagecontext.setattribute (stringname,object value);
Pagecontext.removeattribute (Stringname);
Ways to manipulate other domain objects:
Object getattribute (stringname,int scope)
Scope:pagecontext has a corresponding constant
Pagecontext.application_scope
Pagecontext.session_scope
Pagecontext.request_scope
Pagecontext.page_scope
Voidremoveattribute (String name,int scope)
Voidsetattribute (String name,object value,int scope)
when we only know that there is a name such a parameter, but do not know in which domain. Can be used:
Pagecontext.findattribute (Stringname);
The order of lookups from small to large,Page->request->session->context
c. methods of inclusion and forwarding are provided
Pagecontext.forward (String path);
Pagecontext.include (String Path)
Six. four domain objects
PageContext : Valid on this page
Request : valid in a single request and forwarded servlet
Session : valid in one session, until timeout and destruction
Application : effective throughout the Web app, with a lifetime of Web runtime
Principle: The smaller the domain object, the better.
Seven. JSP built-in tags (action elements)
Jsp:include : Dynamic Inclusion
Jsp:forward : Request Forwarding
Jsp:param : Pass Request parameters
Eight. JavaBean
1. The construction method with no reference
2. private fields (field names start with lowercase)
3. provide public getter and setter methods.
4. java.io.Serialiable (Serializable) interface is generally implemented.
Role: for encapsulating data
Nine. action elements of the JavaBean
1 , Jsp:usebean
Function: Finds an object of the specified name from the specified domain scope. A direct return was found; the instance that created the object was not found and placed in the specified scope.
Scope: Page Request sessionapplication
Property:
ID : The name of the reference object
class : type of Lookup
Scope : The specified range. The default value is page
2 , Jsp:getproperty
Gets the value of the specified property for the specified JavaBean and prints it to the page. If the property value is NULL, print null.
Property:
name : The name of the JavaBean
Property : The getter attribute is manipulated
3 , Jsp:setproperty
Action: Sets the value of a property of JavaBean.
Property:
Property : Property name. Wildcard characters supported *
name : The name of the JavaBean
value : Specify values directly
param : Specifies the name of the requested parameter.
10. The development model of Javaweb
1 , model 1: Jsp+javabean
Features: Ideal for developing very simple applications.
2 , Model 2: Jsp+servlet+javabean (MVC)
M : Model JavaBean
V : View JSP
C : Controller Servlet
jsp--jsp syntax--instruction---Nine implicit objects--Four fields object--jsp--javabean action element--MVC three-tier architecture