1.EL Notes
1. The role of EL
jsp脚本:<%=request.getAttribute(name)%>
The EL expression replaces the script above: ${requestScope.name}
2. Basic writing
The main function of EL is to obtain the data in the four fields, the format ${EL expression}
EL gets the value in the pageContext field: ${pageScope.key};
EL gets the value in the request field: ${requestScope.key};
EL gets the value in the session field: ${sessionScope.key};
EL gets the value in the application field: ${applicationScope.key};
ex:
// 1) Get a normal string, assuming the string exists in the request field $(request.stringName) or $(stringNane) // 2) Get the value of the User object, assuming the User object exists in the request field $(request.user. name) or (user.name) // 3) Get the value of List<User> ${request.userList[0].name} or ${userList[0].name}
Get the name of the WEB application ${pageContext.request.contextPath}
3. 11 built-in objects of EL
1.pageScope 2.requestScope
3.sessionScope 4.applicationScope
5.param,paramValues---- receive parameters equivalent to request.getParameter()
6.header, headerValues --- get the request header, equivalent to request.getHeader(name)
7.initParam --- Get global initialization parameters, equivalent to this.getServletContext().getInitParameter(name)
8.cookie --cookies in WEB development are equivalent to request.getCookies()---cookie.getName()---cookie.getValue()
9.pageContext--pageContext in WEB development and obtaining other eight objects
4. EL execution expression
${1+1},${empty user},${user==null?true:false}
2. JSTL technical notes
1. JSTL overview
JSTL (JSP Standard Tag Library), JSP standard tag library, can be embedded in jsp pages to complete business logic and other functions in the form of tags. The purpose of jstl is to replace the script code in the jsp page, just like el. The JSTL standard standard tag library has 5 sub-libraries, but with the development, his core library is often used at present
Tag library |
URI of the tag library |
prefix |
Core |
http://java.sun.com/jsp/jstl/core |
c |
I18N |
http://java.sun.com/jsp/jstl/fmt |
fmt |
SQL |
http://java.sun.com/jsp/jstl/sql |
sql |
XML |
http://java.sun.com/jsp/jstl/xml |
x |
Functions |
http://java.sun.com/jsp/jstl/functions |
fn |
2. JSTL download and import
1. Download the JSTL JAR package from the Apache website. Go to "http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/" to download the JSTL installation package. jakarta-taglibs-standard-1.1.2.zip, and then decompress the downloaded JSTL installation package. At this time, you can see two JAR files in the lib directory, namely jstl.jar and standard.jar. The jstl.jar file contains the interfaces and related classes defined in the JSTL specification, the standard.jar file contains the .class files used to implement JSTL and the 5 tag library descriptor files (TLDs) in JSTL
2. Use the taglib instruction of jsp to import the core tag library
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3. Common tags of JSTL core library
1. <c:if test=””> tag where test is the condition for returning boolean, use EL expression in test
2. There are two combinations of <c:forEach> tags:
//第一种 <c:forEach begin="0" end="5" var ="i"> ${i}</br> </c:forEach> // Second <forEach items="Collection/Array" var="Variable"> </c:forEach>
3. The development mode of javaEE
1. Technical composition: jsp+servlet+javaBean
Advantages: Use the aspects that each technology is good at in development
servlet: good at processing java business code
jsp: the reality of being good at pages
2. MVC:---- the design pattern of web development
M: Model---Model javaBean: encapsulated data
V: View-----view jsp: simply display the page
C: Controller----Controller Servelt: Get data--encapsulate data--pass data--assign the displayed jsp page
3. Three-tier architecture of javaEE
Server development is divided into three layers
web layer: interact with the client
service layer: complex business processing
dao layer: interact with the database
The three-tier architecture is reflected in the package structure during development practice
What does MVC have to do with three-tier architecture?
It doesn't matter. It can be said that the MVC design pattern is implemented in the web layer of JavaEE, but it doesn't matter at all.