当前位置:网站首页>JSP El expression, JSTL tag
JSP El expression, JSTL tag
2022-07-27 16:59:00 【Not very [email protected]】
Catalog
2、JSTL Tag library ( Example of core label )
1、web Introduce... Into the project jstl Tag library dependency
2、 In the use of jstl Labeled jsp Introduce the tag library on the web page
1、EL expression
--> effect : Get the data in the four domain objects .
grammar : ${xxxScope.key}
We originally passed xxx.getAttribute(key) You can also get the data in the four domains , Why even use EL expression , because EL Expression syntax is more concise .And later we can Of jstl Tag library . If EL Expression not found for key, Returns an empty string "".EL Expression belongs to jsp Or explain later thymeleaf The grammar of
<%@ page import="entity.Student" %>
<%@ page import="java.util.ArrayList" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/16
Time: 14:41
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
pageContext.setAttribute("name","page");
request.setAttribute("name","request");
session.setAttribute("name","session");
application.setAttribute("name","application");
%>
${pageScope.name}
${requestScope.name}
${sessionScope.name}
${applicationScope.name}
</body>
</html>
el expression You can also omit scope ${key} Which object will it get data from . Defaultfrom pageContext Is the scan right key, If so, don't continue scanning , IfIf not, continue scanning request, And so on .
Do not specify a range <br>
${name}<br>
${name}<br>
${name}<br>
${name}<br>2、JSTL Tag library ( Example of core label )
There are some commonly used labels --- such as : Circular label Judgment labels .The purpose of using these labels is to reduce jsp in java Add script code . Enterprises do not recommend largeHome in jsp Too many <%%> This will make the web page more messy . At this time, someone providedJSTL Tag library .
1、web Introduce... Into the project jstl Tag library dependency

2、 In the use of jstl Labeled jsp Introduce the tag library on the web page
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>3、 Application, for example,
3.1、c:foreach label

<!-- Use jstl Tag library loop traversal request Set saved inforEach Traverse :items: Represents the set or array to be traversedvar: Indicates that when traversing a collection , Assign the value of each element in the set only to The variable-->
<%@ page import="entity.Student" %>
<%@ page import="java.util.ArrayList" %><%--
Created by IntelliJ IDEA.
User: Administrator
Date: 2022/5/16
Time: 14:41
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
ArrayList<Student> students = new ArrayList<>();
students.add(new Student("lwh",2,1));
students.add(new Student("bzd",2,0));
students.add(new Student("flj",2,1));
students.add(new Student("wsl",2,0));
request.setAttribute("u",students);
%>
<table border="1" width="500">
<tr>
<th> full name </th>
<th> Age </th>
<th> Gender </th>
</tr>
<c:forEach items="${requestScope.u}" var="student">
<tr>
<td>${student.name}</td>
<td>${student.age}</td>
<td>${student.gender}</td>
</tr>
</c:forEach>
</table>
</body>
</html>
3.2、c:if label

<%@ page import="entity.Student" %>
<%@ page import="java.util.ArrayList" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
<title>$Title$</title>
</head>
<body>
<%
ArrayList<Student> students = new ArrayList<>();
students.add(new Student("lwh",2,1));
students.add(new Student("bzd",2,0));
students.add(new Student("flj",2,1));
students.add(new Student("wsl",2,0));
request.setAttribute("u",students);
%>
<table border="1" width="500">
<tr>
<th> full name </th>
<th> Age </th>
<th> Gender </th>
</tr>
<c:forEach items="${requestScope.u}" var="student">
<tr>
<td>${student.name}</td>
<td>${student.age}</td>
<td>${student.gender}</td>
<c:if test="${student.age>=15}">
<td> Young people </td>
</c:if>
<c:if test="${student.age<15}">
<td> Primary school students </td>
</c:if>
</tr>
</c:forEach>
</table>
</body>
</html>
版权声明
本文为[Not very [email protected]]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/208/202207271449228147.html
边栏推荐
- Measured: the performance of cloud RDS MySQL is 1.6 times that of self built
- jsp-El表达式,JSTL标签
- [paper reading] a CNN transformer hybrid approach for cropclassification using multitemporalmultisensor images
- Segment tree beats~
- (2) Dynamic convolution of dynamic convolution
- [cqoi2012] local minima & Mike and foam
- Automatic classification of e-commerce UGC pictures using Baidu PaddlePaddle easydl
- MQ Series 2: technology selection of Message Oriented Middleware
- JSON data parsing
- After the cubemx is reconfigured, the generated code cannot be opened successfully with IAR
猜你喜欢
随机推荐
json数据解析
If you don't want to step on those holes in SaaS, you must first understand the "SaaS architecture"
The difference between MVC and MVP and MVVM
合工大苍穹战队视觉组培训Day8——视觉,目标识别
C语言之动态内存分配
JSON data parsing
C语言之枚举和联合体
项目练习:表格的查改功能
Build a cloud native file system for media assets
Matplotlib drawing error: "! Latex error: file `type1cm.sty 'not found." solution
Advanced pointer of C language
Embedded interview
Three level cache of pictures in Android
C语言之结构体及位段
D3.js create a cool arc
After the cubemx is reconfigured, the generated code cannot be opened successfully with IAR
ROS - error in running.Py file in the project
Simulation generate report
string数字类型转换为千分位
MPC_ ORCA







![How to modify the decoding clock [chapter]](/img/a7/e55346a081fac0887b294b078a28a5.png)
