Miss Zhu 2022-02-13 08:36:58 阅读数:628
Why use JSTL and EL expression ?
Let's show the information of department employees through a table , Compare JSP and JSTL Different .
The same loop generates a table data , Using tradition jsp:
The same loop generates a table data , Use JSTL The way :
Use loose type conversion , Simplify access to variables and objects .
EL The grammatical structure of is surface reach type , Than Such as say { expression } , for instance surface reach type , Than Such as say {emp.name}
The above variables emp Will follow from page、request、session、application Look for... In turn ,
If you find , Then stop looking for ; If not found , Then return to null
You can also set the range of variables to look for , The attribute range corresponding to the above four built-in objects is EL The writing format in is :pageScope,requestScope,sessionScope,applicationScope
EL Arithmetic operators can also be used in expressions 、 Relational operator 、 Logical operators .
for example :
${
4+5}
${
3<4}
${
3!=4&&5>6}
EL Use :
above EL In fact, it is equivalent to <%=request.getAttribute(“age”)%>. But if so :${sessionScope.age}, from session In the range , You can't get .
EL Expressions simplify the process of outputting information JSP Complexity , But it can't control the process 、 Unable to handle complex logic . Is there a technology , You don't have to write Java Code , And can control the process ?
JSTL Provides a method that does not need to be embedded Java code snippet , You can develop ways to display complex pages
JSTL Provides universal 、 Conditions 、 loop 、 format 、 Database operation and other labels
Use JSTL label , To add the following label to the instruction :
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
JSTL label —— Universal label
<c:out>
The function is to output , Function like <%= Variable %>、 change The amount language Law by : < c : o u t v a l u e = “ word operator strand often The amount ” / > or < c : o u t v a l u e = “ { Variable } The grammar is :<c:out value= “ String constant ”/> or <c:out value= “ change The amount language Law by :<c:outvalue=“ word operator strand often The amount ”/> or <c:outvalue=“{ Variable }” />
<c:set>
The function is to define variables , Store the value of the variable in a JSP In the range , Or is it JavaBean Properties of .
<c:remove>
The functions and set contrary , Remove a variable from a range .
JSTL label —— Condition label
<c:if>
The function is to judge
<c:if test= “ Judge the condition ”>
</c:if>
JSTL label —— Iteration tags
<c:forEach>
The function is to iterate over a collection containing multiple objects , Follow Java The unary cycle in is similar
<c:forEach [var= “ The current element ”] items= “ aggregate ”>
</c:forEach>
JSTL label —— format
<fmt:formatDate value="${ date }" pattern=“yyyy-MM-dd” />
<fmt:parseDate value=" Date string "pattern=“yyyy/MM/dd”/>
JSTL Labels and EL Expression summary :
copyright:author[Miss Zhu],Please bring the original link to reprint, thank you. https://en.javamana.com/2022/02/202202130836551099.html