这里给大家展示一段回显数据的代码块
这段代码块中使用了el表达式是代码稍微简单了一点
那,能不能更简单呢~
有,那就是JSTL标签库
回顾一下,el表达式是取值用的
JSTL:分支(一定要配合EL表达式一起连用)
理由:JSTL做分支的时候需要做判断和计算,计算需要数据,那数据就要从EL表达书中来
JSTL:java server tag lib java服务端的标签库
一组标签,用在服务端(jsp中)
使用步骤
(1)引入标签库
taglib指令
Idea不识别jstl的解决办法
在tomcat/lib中拷贝两个jar包
百度网盘 请输入提取码
俩jar包我放自己百度云盘里了,自己领哈
关联tomcat时,添加jar包
Jstl标签又称为c标签
(2)使用标签
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
jstl01
<%
request.setAttribute("age" , 16);
%>
${age}岁了,成年了
${age}岁了,未成年
Jstl中,没有else标签的,可以通过多重if来转化
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
jstl02
<%
request.setAttribute("age" , 16);
%>
${age}岁了,成年了
${age}岁了,未成年
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.njwbhz.entity.Goods" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
jstl03
<%
Goods goods1 = new Goods(1 , "红富士苹果" , 10);
Goods goods2 = new Goods(2 , "苹果手机" , 5000);
Set goodsSet = new HashSet();
goodsSet.add(goods1);
goodsSet.add(goods2);
request.setAttribute("goodsSet" , goodsSet);
%>
<%--循环遍历集合--%>
${goods.name}
扩展:输出,
第一个商品的名称:xxx
第二个商品的名称:yyy
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="com.njwbhz.entity.Goods" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
jstl04
<%
Goods goods1 = new Goods(1 , "红富士苹果" , 10);
Goods goods2 = new Goods(2 , "苹果手机" , 5000);
Set goodsSet = new HashSet();
goodsSet.add(goods1);
goodsSet.add(goods2);
request.setAttribute("goodsSet" , goodsSet);
%>
<%--循环遍历集合--%>
第${status.index + 1}个商品的名称:${goods.name}
注册功能中加入el+jstl标签
regist.jsp



