日月的弯刀  
Where Amazing Happens!

 


JSTL标签

使用时需要用taglib指令导入一句话  
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>  
 
或者将jstl库导入tomcat中的lib包中
核心标签库:
            输出标签:
                        <c:out value="数据"></c:out>(很少用)
            设置作用域标签:
                        <c:set var="键名" value="值" scope="作用域名" ></c:set>
                        相当于我们写的java代码中的作用域名.setAttribute(键名,值);
                        往指定作用域中存储数据,默认是pageContext
            删除标签:
                    <c:remove var="键名" scope="作用域名" ></c:remove>
                    删除指定作用域中的数据,默认四个作用域全部删除
            逻辑标签:
                <c:if test="$+{逻辑判断}" ></c:if>---想当于java中的if判断
 
                <c:choose>------------------------相当于java中的if(){}else if(){}...else{}
                    c:when test="" /c:when>
                    c:when test="" /c:when>
                    c:otherwise /c:otherwise
                </c:choose>
                
                <c:forEach items="要遍历的对象,使用el表达式获取" var="记录每次的循环结果"
                            begin="开始" end="结束" step="步长(相当于i++)" varStatus="记录每次循环的状态">
                    ${i}-${vs.index}-${vs.count}-${vs.first}-${vs.last} >
                </c:forEach>    
                
        函数标签库:
        SQL标签库:
        XML标签库:
        格式化标签库:  

JSTL实例标签演示

<%
pageContext.setAttribute("s","哈哈");
request.setAttribute("s","jstl东西不多,主要就有几个重要的标签的用法");
session.setAttribute("s", "呵呵");
application.setAttribute("s", "嘻嘻"); 
%>
 
<c:out value="666"></c:out>---<c:out value="${s2}" default="jstl学习"></c:out>------${s}--<%=request.getAttribute("s") %>
  

页面输出结果:666---jstl学习------哈哈--jstl东西不多,主要就有几个重要的标签的用法

<%pageContext.setAttribute("a","123");%>  
<c:set var="a" value="123"></c:set>

<c:set var="req" value="helloRequest" scope="request"></c:set>--<%request.setAttribute("req", "helloRequest"); %>
<c:out value="${requestScope.req}"></c:out><br />
<c:remove var="s" scope="page"/>  
<c:if test="${1==1}">
      <i>今天天气很好</i>
</c:if>  
  <c:set var="a" value="60"></c:set>
  <c:choose>
      <c:when test="${a>90}">
          <u>优秀</u>
      </c:when>
      <c:when test="${a<=90&&a>=70}">
          <u>良好</u>
      </c:when>
      <c:otherwise>
          <u>男女混合双打</u>
      </c:otherwise>
  </c:choose>  
<c:forEach begin="0" end="3" var="i">
      11111--${i}<br>
</c:forEach>  

页面输出结果:
 
 
 
<c:forEach var="i" begin="1" end="9">
      <c:forEach var="j" begin="1" end="${i}">
          ${i}*${j}=${i*j}   
      </c:forEach>  
      <br />
</c:forEach>  
 
页面输出结果:
 
 

 
 
ArrayList list=new ArrayList();
      list.add("a");
      list.add("b");
      list.add("c");
      list.add("d");
      list.add("e");
request.setAttribute("list",list);  


页面输出结果:
 
 
 
HashMap hs=new HashMap();
      hs.put("a1","哈哈");
      hs.put("a2","呵呵");
      hs.put("a3","嘿嘿");
      request.setAttribute("hs",hs);  
 
页面输出结果:
 

 
 


 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
posted on 2017-03-12 14:57  日月的弯刀  阅读(251)  评论(0编辑  收藏  举报