JSTL备忘

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,也可以实现传入参数的功能;
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值