JSP标签学习笔记(内置标签+JSTL标签)
来源:互联网 发布:淘宝优惠券微信公众号 编辑:程序博客网 时间:2024/05/21 13:22
二.JSP标签
作用:
1.流程判断
2.跳转页面
….
分类:
1.内置标签:不需要在JSP页面导入标签
2.jstl标签:需要在JSP页面中导入标签
3.自定义标签:开发者自定义,需要在JSP页面导入标签
动态标签:
1.转发标签:
2.参数标签:
3.包含标签:
1.内置标签
- 转发标签
index.jsp主要代码
<jsp:forward page="index2.jsp"> <jsp:param name="mahan" value="huan"></jsp:param> </jsp:forward>
index2.jsp
<%-- Created by IntelliJ IDEA. User: pc Date: 17-4-14 Time: 下午4:37 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>Title</title></head><body><%=request.getParameter("mahan")%></body></html>
- 包含标签
index.jsp主要代码
<jsp:include page="head.jsp"></jsp:include> 上面是头部
head.jsp代码
<%-- Created by IntelliJ IDEA. User: pc Date: 17-4-14 Time: 下午4:46 To change this template use File | Settings | File Templates.--%><%@ page contentType="text/html;charset=UTF-8" language="java" %><html><head> <title>Title</title></head><body><h1>我是头部</h1></body></html>
2.jstl标签
全名(java standard tag libarary) java标准标签库
1.核心标签库(C标签库)–重点
2.国际哈化标签库(fmt标签库)
3.EL函数库(fn函数库)
4.XML标签库(x标签库)–次要
5.sql标签库(sql标签库)–次要
- 核心标签库
保存数据:
获取数据:
单条件判断:
<多条件判断>
循环数据:
重定向 :
1)导入jstl支持的jar包:下载地址 密码: g853
2)导入标签库
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
3)标签
a.保存数据:.
默认将数值存入page域中
<c:set var="mahuan" value="huanhuan"></c:set>${mahuan}
scope=”域对象”(page,request,session,application)
<c:set var="mahuan" value="huanhuan" scope="request"></c:set>${requestScope.mahuan}
b.获取数据:
从域中获取数值
<c:set var="mahuan" value="huanhuan" scope="request"></c:set><c:out value="${mahuan}"></c:out>
default=”默认值” 当值为null时显示默认值
escapeXml=” “(true false)是否对value的值进行转义默认转义(true)
<% String str =null; pageContext.setAttribute("aaa",str);%><c:out value="${aaa}" default="<h2>默认值</h2>" escapeXml="false"></c:out>
c.单条件判断:
test=” “(true false)判断是否要输出
<c:if test="true"> 判断输出</c:if>
<c:if test="${30>22}"> 判断输出</c:if>
d.<多条件判断>
<c:set var="mahuan" value="78" ></c:set><c:choose> <c:when test="${mahuan>90 && mahuan<=100}"> 特等奖 </c:when> <c:when test="${mahuan>80 && mahuan<=90}"> 一等奖 </c:when> <c:when test="${mahuan>70 && mahuan<=80}"> 二等奖 </c:when> <c:when test="${mahuan>60 && mahuan<=70}"> 三等奖 </c:when> <c:otherwise> 参赛奖 </c:otherwise></c:choose>
e.循环数据:
begin= ” ” 从那个元素开始遍历,默认从0开始
end=” ” 到那个数据结束,默认到最后一个结束
step=“ ” 步长 默认为1
items=“ ” 需要遍历的数据集合
var=“ ” 每个元素的名称
varStatus= “ ” 当前正在遍历元素的状态对象(count属性:当前位置,从1开始)–序列
list集合:
“`
<%
List list= new ArrayList();
list.add(new Student(“张三”,”21”));
list.add(new Student(“小明”,”32”));
list.add(new Student(“小花”,”44”));
pageContext.setAttribute(“list”,list);
%>
序号:
![](http://upload-images.jianshu.io/upload_images/1616232-184e7ca71a863c03.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)map集合:
<%
Map
![](http://upload-images.jianshu.io/upload_images/1616232-4e8aaa641bf77256.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)>f.<c:forTokens items="" delims=""> </c:forTokens>循环特殊字符串
<%
String sr = “ma-huan-huan-ni-hao”;
pageContext.setAttribute(“huan”,sr);
%>
${s}
![](http://upload-images.jianshu.io/upload_images/1616232-b669cdf7aa20684d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)>g.<c:redirect></c:redirect>重定向
“`
- ##完
文集:JavaEE–学习笔记
- JSP标签学习笔记(内置标签+JSTL标签)
- JSP学习笔记(四):JSTL标签
- JSP标签(JSTL)
- JSTL标签学习笔记
- jsp标准标签&jstl标签用法笔记
- JSP学习笔记(四)------JSTL外链标签库
- jsp(jstl标签)学习网址
- jstl标签(jsp标准标签库)
- JSP标签-JSTL-自定义标签
- jstl fmt 标签学习笔记
- JSTL标签库学习笔记
- JSTL标签库学习笔记
- jsf标签,jsp标签与jstl标签
- JSP学习笔记(三)---JSTL标签核心库
- JSP学习笔记—EL表达式和JSTL标签详解
- jsp---JSTL标签详解
- JSP JSTL fn标签
- JSP: JSTL标签详解
- EL表达式笔记
- Mybatis总结(1)---基本知识
- 【C++学习笔记】控制台与文本的输入输出
- 决策树——选择最好的划分方法之信息熵
- 克隆二叉树
- JSP标签学习笔记(内置标签+JSTL标签)
- UISCROLLVIEW 在ios8 view显示出来后 contentoffset 被置位 (零, -64)的原因
- php+android 搭建后台及显示
- MVC开发模式
- Ajax学习笔记
- CF#410(Div.2) 解题报告
- Ajax小案例:验证表单中用户名是否可用
- Qt Meta Type System
- String和StringBuffer的区别