Article Directory
1. EL overview
1. What is EL
EL (Expression Language) is to make JSP easier to write; it provides a way to simplify expressions in JSP, making JSP code more simplified.
2. EL function
EL and JSTL are used together to replace the writing of embedded Java code in JSP pages;
3. EL function
- retrieve data;
- Perform calculations;
- Get the objects commonly used in web development;
4. EL syntax
${EL 表达式}
2. EL access to data
1. How EL gets data
- When the EL expression is executed, the pageContext.findAttribute() method will be called;
- Find the corresponding objects from the scope of page, request, session, and application respectively;
- If found, return the corresponding object, if not found, return "" (not null, it is an empty string);
- The data obtained by EL must be in four scopes;
2. Example
Three, EL access to data in arrays and collections
1. EL get array data
2. Get the data of the List collection
3. Get the data of the Map collection
Four, EL execution calculation
1. Arithmetic operations
2. Relational operations
3. Logic Operations
4. Ternary Operation
Five, EL access to common objects in web development
1. What are the commonly used objects
EL expression defines 11 common objects in web development;
name | meaning |
---|---|
pageContext | Equivalent to pageContext in JSP built-in object |
pageScope | Get the data of the name under the specified domain |
requestScope | Get the data of the name under the specified domain |
sessionScope | Get the data of the name under the specified domain |
applicationScope | Get the data of the name under the specified domain |
param | Receive request parameters in the page (receive a parameter with a name corresponding to a value) |
paramValues | Receive request parameters in the page (receive a parameter with a name corresponding to multiple values) |
header | Get the request header on the page (get a key corresponds to a value header) |
headerValues | Get the request header on the page (get a key corresponds to multiple value headers) |
cookie | The name and value of the access cookie (${cookie.key.name} ${cookie.key.value}) |
initParam | Get the value of the global initialization parameter |
2. Example
Six, JSTL overview
1. What is JSTL
JSTL (Java server pages standarded tag library, namely JSP standard tag library) is a standard specification made by JCP (Java community Proces), it mainly provides Java Web developers with a standard and common tag library; developers can use these tags Replace the Java code on the JSP page, thereby improving the readability of the program and reducing the difficulty of program maintenance.
2. JSTL Tag Library
c tag (core tag library)
fmt tag
xml tag
sql tag
jstl function library
Seven, JSTL introduction
- Introduce the jar package of JSTL
- New JSP page
- Introduce tag library
- Use JSTL
8. JSTL if tag (judgment)
1. Example
2. Attributes of if tag
- test attribute: condition;
- var attribute: assign the condition in test to a variable, and define the variable in var;
- scope attribute: scope of action;
Nine, JSTL's foreach tag (loop)