JSTL备忘
来源:互联网 发布:短域名生成器自定义 编辑:程序博客网 时间:2024/06/06 14:29
jstl(jsp标准标签库)学习:
表达式相关标签: <c:out> <c:set> <c:remove> <c:catch>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:set value="21" var="num"/>
<c:out value="${num}"/>
<c:set var="num">21</c:set>
<c:out value="${num }"/>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>
</title>
</head>
<body>
<c:set value="21" var="num"/>
<c:remove var="num"/>
<c:out value="${num }"/>
</body>
</html>
流程控制相关标签:<c:if> <c:choose> <c:when> <c:otherwise>,其中<c:choose>标签是<c:when>和<c:othwise>的父标签:
<c:choose>
<c:when test="">
</c:when>
<c:when test="">
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
且<c:choose></c:choose>中至少要有一个<c:when>标签,而<c:otherwise>标签则可以没有,还有就是<c:when>标签必须放在<c:otherwise>标签的前面,
只有当<c:when>全为假时才会执行<c:otherwise>里面的内容,最后一个就是当有多个<c:when>为真的话,只会执行第一个<c:when>里面的东西;(很像switch语句)
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:set value="电子工业出版社" var="publisher"/>
<c:if test="${publisher=='电子工业出版社'}" var="namecheck">
检查正确!
</c:if>
<c:out value="${namecheck}"/>
<c:set value="电子工业出版社" var="publisher"/>
<c:choose>
<c:when test="${publisher=='电子工业出版社'}">
电子工业出版社!
</c:when>
<c:when test="${publisher=='机械工业出版社'}">
机械工业出版社!
</c:when>
<c:otherwise>
本书出版社不明!
</c:otherwise>
</c:choose>
</body>
</html>
迭代相关标签: <c:forEach> <c:forTokens>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String name=new String("姓名=邓佳容|年龄=10个月|性别=女");
request.setAttribute("name",name);
%>
<c:forTokens items="${name}" var="currentName" varStatus="currentVarStatus" delims="|">
当前元素为:<c:out value="${currentName}"/>
当前索引号为:<c:out value="${currentVarStatus.index}"/>
当前迭代次数为:<c:out value="${currentVarStatus.count}"/><hr>
</c:forTokens>
<c:forTokens items="${name}" var="currentName" varStatus="currentVarStatus" delims="|">
<c:forTokens items="${currentName}" var="currentName1" varStatus="currentVarStatus" delims="="> //这里相当于两层循环,先用"|"分割,再用"="分割 "
当前元素为:<c:out value="${currentName1}"/>
当前索引为:<c:out value="${currentVarStatus.index}"/>
当前迭代次数为:<c:out value="${currentVarStatus.count}"/>
</c:forTokens>
</c:forTokens>
</body>
</html>
URL相关标签: <c:import>与<c:param> <c:redirect> <c:url>
<c:import>标签用于把当前JSP页面之外的其他静态或动态文件包含进来,功能类似于JSP的动作指令<jsp:include>,但两者有所差别:<jsp:include>只能包含与当前JSP页面处于同一个Web应用下的文件,而<c:import>标签无此限制,甚至可以是其他网站的文件,在<c:import>与</c:import>中加入<c:param></c:param>标签的话还可以实现向import的URL传入参数的功能。
<c:redirect>是重定向到一个新的URL,也可以实现传入参数的功能;
<c:url>是生成一个新的URL,也可以实现传入参数的功能;
表达式相关标签: <c:out> <c:set> <c:remove> <c:catch>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:set value="21" var="num"/>
<c:out value="${num}"/>
<c:set var="num">21</c:set>
<c:out value="${num }"/>
</body>
</html>
<%@ page contentType="text/html;charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<html>
<head>
<title>
</title>
</head>
<body>
<c:set value="21" var="num"/>
<c:remove var="num"/>
<c:out value="${num }"/>
</body>
</html>
流程控制相关标签:<c:if> <c:choose> <c:when> <c:otherwise>,其中<c:choose>标签是<c:when>和<c:othwise>的父标签:
<c:choose>
<c:when test="">
</c:when>
<c:when test="">
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
且<c:choose></c:choose>中至少要有一个<c:when>标签,而<c:otherwise>标签则可以没有,还有就是<c:when>标签必须放在<c:otherwise>标签的前面,
只有当<c:when>全为假时才会执行<c:otherwise>里面的内容,最后一个就是当有多个<c:when>为真的话,只会执行第一个<c:when>里面的东西;(很像switch语句)
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<c:set value="电子工业出版社" var="publisher"/>
<c:if test="${publisher=='电子工业出版社'}" var="namecheck">
检查正确!
</c:if>
<c:out value="${namecheck}"/>
<c:set value="电子工业出版社" var="publisher"/>
<c:choose>
<c:when test="${publisher=='电子工业出版社'}">
电子工业出版社!
</c:when>
<c:when test="${publisher=='机械工业出版社'}">
机械工业出版社!
</c:when>
<c:otherwise>
本书出版社不明!
</c:otherwise>
</c:choose>
</body>
</html>
迭代相关标签: <c:forEach> <c:forTokens>
<%@ page language="java" contentType="text/html; charset=gb2312"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String name=new String("姓名=邓佳容|年龄=10个月|性别=女");
request.setAttribute("name",name);
%>
<c:forTokens items="${name}" var="currentName" varStatus="currentVarStatus" delims="|">
当前元素为:<c:out value="${currentName}"/>
当前索引号为:<c:out value="${currentVarStatus.index}"/>
当前迭代次数为:<c:out value="${currentVarStatus.count}"/><hr>
</c:forTokens>
<c:forTokens items="${name}" var="currentName" varStatus="currentVarStatus" delims="|">
<c:forTokens items="${currentName}" var="currentName1" varStatus="currentVarStatus" delims="="> //这里相当于两层循环,先用"|"分割,再用"="分割 "
当前元素为:<c:out value="${currentName1}"/>
当前索引为:<c:out value="${currentVarStatus.index}"/>
当前迭代次数为:<c:out value="${currentVarStatus.count}"/>
</c:forTokens>
</c:forTokens>
</body>
</html>
URL相关标签: <c:import>与<c:param> <c:redirect> <c:url>
<c:import>标签用于把当前JSP页面之外的其他静态或动态文件包含进来,功能类似于JSP的动作指令<jsp:include>,但两者有所差别:<jsp:include>只能包含与当前JSP页面处于同一个Web应用下的文件,而<c:import>标签无此限制,甚至可以是其他网站的文件,在<c:import>与</c:import>中加入<c:param></c:param>标签的话还可以实现向import的URL传入参数的功能。
<c:redirect>是重定向到一个新的URL,也可以实现传入参数的功能;
<c:url>是生成一个新的URL,也可以实现传入参数的功能;
- JSTL备忘
- JSTL备忘
- jstl/el 备忘
- JSTL使用备忘
- jstl 使用备忘
- 2、JSTL备忘
- jstl标签使用(备忘)
- 项目期间,简单备忘...JSTL之if
- 项目期间..简单备忘..JSTL之foreach
- 备忘:现有项目JSTL使用汇总
- 项目期间..简单备忘...JSTL之读取集合Map
- 项目期间..简单备忘..JSTL之格式化输出
- jstl
- jstl
- JSTL
- jstl
- JSTL
- JSTL
- 五种提高 SQL 性能的方法
- 附录A 程序维护手册格式说明
- 深入理解ASP.NET的Postback
- 单片机中关键字data,idata,xdata,pdata的区别
- Svg下的坐标变换
- JSTL备忘
- linux中禁用ipv6
- 让.Net2.0的Membership使用已存在的Sql Server2000/2005数据库
- 使用 WinSock 2 实现多址广播
- MFC应用程序中处理消息的顺序
- CEO CFO CIO CTO CKO CHO CMO CNO CQO CBO CCO CVO 英文定义
- [翻译] 怎么在ASP.NET 2.0中使用Membership
- 分析一下CSDN论坛中一个比较字段值保留最大并删除其它的帖子
- NT、Novell、Unix服务器的互连