备忘:现有项目JSTL使用汇总
来源:互联网 发布:c语言游戏源代码 编辑:程序博客网 时间:2024/06/06 13:10
准备公用页面,供其它页面进行引用:tablibs.jsp
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%><%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%><%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%><c:set var="ctx" value="${pageContext.request.contextPath}"/>
JSP页面调用方式
<%@ include file="/taglibs.jsp"%>
用法
设置变量标签
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
条件标签
//字符串比较<c:if test="${xxx eq '1'}">selected="selected"</c:if><c:if test="${aaa ne '3'}">selected="selected"</c:if>//数值比较<c:if test="${xxx==0}">selected="selected"</c:if><c:if test="${xxx!=0}">selected="selected"</c:if><c:if test="${xxx>0}">selected="selected"</c:if><c:if test="${xxx<0}">selected="selected"</c:if><c:if test="${xxx>=0}">selected="selected"</c:if><c:if test="${xxx<=0}">selected="selected"</c:if>//数值计算<c:if test="${index%2==0}">selected="selected"</c:if><c:if test="${money/10000>=10000}">selected="selected"</c:if><c:if test="${aaa-bbb>0}">selected="selected"</c:if>//变量比较<c:if test="${aaa eq bbb }"> selected="selected"</c:if><c:if test="${aaa ne bbb }"> selected="selected"</c:if>//多条件<c:if test="${empty xxxList || xxxList.length eq '1' }">selected="selected"</c:if><c:if test="${aaa && bbb eq '1' && ccc ne '2'}">selected="selected"</c:if>//boolean值,xxx为true或false<c:if test="${xxx}">selected="selected"</c:if>//是否不为空,用于list<c:if test="${!empty xxxList}">selected="selected"</c:if><c:if test="${!empty aa.xxxList}">selected="selected"</c:if>//是否为空,用于list<c:if test="${empty xxxList}">selected="selected"</c:if><c:if test="${empty aa.xxxList}">selected="selected"</c:if>
迭代标签
<c:forEach items="${xxxList}" var="record" varStatus="status"> //xxxList:系统返回的列表 //record:本次循环中定义的变量 //status:列表状态 ${status.count}//列表计数</c:forEach><c:forEach var="img" items="${fn:split(xxx,',')}"> //使用fn.split将xxx用“,”分隔后做为list,供forEach使用</c:forEach>
选择标签
<c:choose> <c:when test="条件1"> //test的用法同if test </c:when> <c:when test="条件2"> </c:when> ..... <c:when test="条件N"> </c:when> <c:otherwise> //条件都不满足时 </c:otherwise></c:choose>
格式化标签
//数值格式化<fmt:formatNumber value="${money}" pattern="#0.00"></fmt:formatNumber><fmt:formatNumber value="${money}" pattern="###0.00"></fmt:formatNumber>//时间格式化<fmt:formatDate var="nowStr" value="${nowDate}" pattern="yyyy/MM/dd HH:mm:ss"/>//时间字符串解析<fmt:parseDate var="create_date" value="${nowDate}" pattern="yyyy-MM-dd HH:mm:ss"/>
字符串处理函数
注意函数与标签的位置
//求长度<c:if test="${fn:length(content) > 20}"></c:if>//分隔<c:forEach items="${fn:split(content,',')}" var="rd"></c:forEach>//字符串截取${fn:substring(content,0,10)}
实例
下拉菜单
<select name="status"> <option></option> <option value="1" <c:if test="${status eq '1'}">selected="selected"</c:if> >已到账</option> <option value="2" <c:if test="${status eq '2'}">selected="selected"</c:if> >未到账</option> <c:forEach var="record" items="list" varStatus="st"> <option value="${record.key}" <c:if test="${record.key eq '2'}">selected="selected"</c:if> >${record.value}</option> </c:forEach></select>
Input Radio
<input type="radio" value="1" name="status" <c:if test="${status eq '1' }">checked="checked"</c:if>>已到账<input type="radio" value="2" name="status" <c:if test="${status eq '2' }">checked="checked"</c:if>>未到账
阅读全文
0 0
- 备忘:现有项目JSTL使用汇总
- JSTL使用备忘
- jstl 使用备忘
- jstl标签使用(备忘)
- jstl标签使用汇总
- 项目期间,简单备忘...JSTL之if
- 项目期间..简单备忘..JSTL之foreach
- JSTL备忘
- JSTL备忘
- Android开源项目汇总-个人备忘
- 项目期间..简单备忘...JSTL之读取集合Map
- 项目期间..简单备忘..JSTL之格式化输出
- React Native在现有项目中的使用
- 使用Nuxt.js改善现有项目
- JSTL标签项目中的使用
- 项目中jSTL的使用
- jstl/el 备忘
- 2、JSTL备忘
- Centos7 使用yum源安装mysql5.7
- 图解HTTP读书笔记-(七 确保安全的HTTPS)
- Gabor特征总结
- 1633:核桃的数量
- 342. Power of Four
- 备忘:现有项目JSTL使用汇总
- 内存泄露检测工具使用
- map
- javamail模拟邮箱功能发送电子邮件-基础实战篇(javamail API电子邮件实例)
- mysql数据库数据修改后,保存刷新数据还原了
- [Android]在Android TV中实现组合按键的监听触发功能
- 希尔排序c++
- 【PDF下载】红包在线技术峰会之微博红包技术实践
- 成功如此