当前位置:网站首页>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
边栏推荐
猜你喜欢

Niuke topic -- symmetric binary tree

2021 national vocational college skills competition (secondary vocational group) network security competition questions (9) ideas

OpenCV(三)——图像分割

Cvxpy - latest issue

C语言之指针进阶

Character function, string function and memory function of C language

D3.js create a cool arc

Structure and bit segment of C language

京东张政:内容理解在广告场景下的实践和探索

C语言之数组
随机推荐
Gurobi——GRBModel
kubesphere多节点安装出错
In addition to "adding machines", in fact, your micro service can be optimized like this
Servlet uses cookies to realize the last login time of users
MPC5744p时钟模块
Jerry's maximum volume prompt sound cannot be broadcast [article]
Character function, string function and memory function of C language
js中的函数
京东张政:内容理解在广告场景下的实践和探索
除了「加机器」,其实你的微服务还能这样优化
Segment tree beats~
Embedded interview
Pointer elementary of C language
mysql视图及存储过程
内置对象(下)
Fast Planner - detailed explanation of kinetic astar
Gurobi——GRBEnv
移动端页面布局
md 中超链接的解析问题:解析`this.$set()`,`$`前要加空格或转义符 `\`
Program environment and preprocessing of C language