First, the JSP part
As long as it is related to the page display is the focus
1. Script for JSP
<%java code%>: Translated into service method interior, local variables, local functions
<%= expression or variable%>: Translated into service method Out.write (expression or variable)
<%!java code%>: The global content, method, global variable that is translated into the servlet
2. How the JSP works
JSP translated into servlet at run time
index.jsp------>work/index_jsp.java----->work/index_jsp.class
3. Comments for JSP
HTML comment:<!--annotation-visible Range: HTML source visible
Java Comment: note written to script///**//***/visible range: translated servlet
JSP Comment: <%--annotation--%> visible Range: JSP source range visible
4. Instructions for JSP
JSP Directive: Page directive taglib Directive include directive
General format for JSP directives: <%@ directive Name attribute = Attribute Value Property = property value%>
(1) Page directive
Configure information for the entire JSP
Property:
Script in language:jsp can embed language code only embedded Java default embedded Java
Import: Importing packages in a JSP
Pageencoding: The code inside of the JSP itself already contains ContentType
ContentType: Translated into Response.setcontenttype ("text/html; CHARSET=GBK ");
Errorpage:jsp the address of the jump after the error
The Iserrorpage:true representative itself is an error-handling page
iselignored:jsp whether the El expression can be resolved by default is False can parse
Session: Whether to create session automatically
The size of the buffer:out buffer can be set to 0KB
(2) Taglib directive
Introducing Tag Libraries
<%@ taglib uri= "" prefix= ""%>
<%@ taglib uri="Http://java.sun.com/jsp/jstl/core" prefix="C" %>
(3) include directive
Contains pages with----static inclusions
<%@ include file="/jsp/j2.jsp" %>
5. The nine implicit objects of JSP (interview written Test frequently asked)
What is an implicit object?
Objects that are used directly in JSP scripts
Request
Response
PageContext
Session
Application
Config
Out
Page
exception
which
Out object: JspWriter
Out.write ()----> page Write content
PageContext object: Context object for the page
1) PageContext is a domain object
Visible Range: Current JSP page
SetAttribute (Name,value)
GetAttribute (name)
RemoveAttribute (name)
SetAttribute (Name,value,scope)
GetAttribute (Name,scope)
RemoveAttribute (Name,scope)
Where scope is the specified domain scope
Pagecontext.setattribute ("name", "Zhangsan", Pagecontext.session_scope);
Findattribute (name);
Bottom-up implementation: Looking for attributes from four domains from small to large in order to find properties after the domain is not looking for
Page domain---->request domain----->session domain----->application domain
${requestscope.name}
${name}-----Bottom Findattribute ()
2) PageContext can get other eight hidden objects
6. JSP tags (JSP actions)
<jsp:include>----interview Frequently asked
Include page----dynamic inclusion
What is the difference between static inclusion and dynamic inclusion?
Static inclusion: The included JSP is first merged with the included JSP at the source level and then translated into a servlet
Dynamic inclusion: Translate two JSPs Separately, and merge the results in the run phase
<jsp:forward>
<jsp:param>
<jsp:useBean>
<jsp:setProperty>
<jsp:getProperty>
Two, El expression
E L (Expression Language) Purpose: To make JSP easier to write
1. El can get data from a domain
${pagescope.name}
${requestscope.name}
${sessionscope.name}
${applicationscope.name}
${name}
2. El can perform operations
${1+1}
${name== ' Zhangsan '? True:false}
${list[2].name== ' Aaa3 '? equals ":" Does Not Equal "}
Keyword empty
${empty objects/variables in the domain}----->true/false
3. El's Built-in Objects 11 (Learn)
Pagescope Requestscope Sessionscope Applicationscope
PageContext
${pagecontext.request.contextpath}
4. El Call function (method)
Steps to use:
1) Introduction of the El Function library
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="FN" %>
2) Use the EL function on the JSP page
Syntax: ${FN: function (Parameter)} return value is the result of processing
${fn:touppercase ("Ahdkjalskhd")}
---->ahdkja ....
Three, jstl Tag library
JSTL (JSP standard tag library,jsp tag library), instead of logic code in JSP scripts
1. Jstl the composition of the label
Tag Library function description |
The URI of the tag library |
Recommended prefixes |
Core Tag Library |
Http://java.sun.com/jsp/jstl/core |
C |
XML Tag Library |
Http://java.sun.com/jsp/jstl/xml |
X |
Internationalization / formatting Tag library |
Http://java.sun.com/jsp/jstl/fmt |
Fmt |
Database Tag Library |
Http://java.sun.com/jsp/jstl/sql |
Sql |
EL function |
Http://java.sun.com/jsp/jstl/functions |
Fn |
2. Jstl's core library
Development steps:
1) page introduces Jstl Core library <%@ taglib%>
2) Use the JSTL Core Library tab on the page
JSTL Tags:
<c:forEach>
Two ways to use:
A) Items+var+varstatus
b) Begin+end+var
<c:if>
Test property: Internal is a Boolean judgment
<c:set>
Set data directly to a domain
var: the name of the data in the domain
Value: The value of the data in the field
Scope: which domain
Java combat 04javaweb-04jsp, El expression, jstl tag library