代码拉取完成,页面将自动刷新
${key}
${域对象.属性}
或 ${域对象[属性值]}
后者常用于处理属性值带有特殊符号的情况) 四大域分别对应的取值对象为
session : sessionScope
application : applicationScope
pageContext : pageScope
request : requestScope
四大域的大小为:
pageContext < request < session < application
${pageContext.request.contextPath}
等价于${pageContext.request.getContextPath()}
<%@taglib prefix="前缀" uri="需要的库"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
//判断javabean是否为空
原始写法
<%
if(products == null){
%>
<td colspan="4">暂无商品</td>
jstl写法,products直接从setAttribute中拿的
<c:if test="${products == null}">
<td colspan="4">暂无商品</td>
</c:if>
//循环javabean
原始写法
<%
}else{
for(Products p : products){
%>
<tr>
<td><%= p.getId() %></td>
<td><%= p.getPname() %></td>
<td><%= p.getPprice()%></td>
<td><%= p.getPdesc() %></td>
</tr>
<%
}
}
%>
新的写法,products直接从setAttribute中拿的
<c:if test="${products != null}">
<c:forEach items="${products}" var="p">
<tr>
<td>${p.id}</td>
<td>${p.pname}</td>
<td>${p.pprice}</td>
<td>${p.pdesc}</td>
</tr>
</c:forEach>
</c:if>
demo
<c:forEach begin="1" end="10" step="1" var="i">
${i}
</c:forEach>
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。