Standard Tag Library JSTL【1】



JSP      ( Standard Tag Library , JSTL)                  Web          。

JSP                  。     JSP   ,  jsp:include   ,                                   。            (    taglib) ,                          。      taglib          ,               ,     Web            。

      

       JSTL          JSP      。          ,      (     JAVA   )            ,                 , JSTL                            。

 

 .    JSTL

 

     JAR   , jstl.jar   standard.jar 。        ,    ( 1+1 ? =2 ,        ,          。)。

 

    :

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

                                                                

 . Core    

 

Core                、    、      URL      。  JSP      Core   ,    taglig   ,        ,  :

<%@ taglib rui=”http://java.sun.com/jsp/jstl/core”  prefix=”c” %>

 

         <c:out> 、 <c:set> 、 <c:remove> 、 <c:cath>

1.<c:out>

               。    JSP   <%=%>    ,    EL   $ ${el-expression} 。

 

2.<c:set>

             javabean      。

      :

<c:set var=”username” value=”lisi” scope=”session”/>

          session 。

 

3.<c:remove>

   <c:set>           。  : <c:remove var=”nusername” scope=”session”/>

 

4.<c:catch>

 

                    ,            。

                     :<c:catch>       :</c:catch>   。          ,        ,    var       ,       page   。        ,  var             。

       var   ,          ,          。

Eg :

<c:catch var=”exception”>

<%

       int i = 5;

       int j = 0;

       int k=i/j;

%>

</c:catch>

<c:out value=”${exception}” /><br>

<c:out value=”${exception.massage}”/>

      : exception.getMessage()

 

       <c:if><c:choose><c:when><c:otherwise>

1.<c:if>

     java    if     。

 

<c:if test=”${user.visitCount==1}”>

       This is your first visit .

</c:if>

 

   true ,       。      var ,       。

<c:if test=”${param.name==’admin’}” value=”result”/>

<c:out value=”${result}” />

 

2.<c:choose>

<c:choose>   <c:when> 、 <c:otherwise>           ,    java    if else.

<c:choose>      <c:when> 、 <c:otherwise>     。

eg :

<c:choose>

       <c:when test="${row.v_money<10000}">

                  

       </c:when>

       <c:when test="${row.v_money>=10000&&row.v_money<20000}">

                  

       </c:when>

       <c:otherwise>

                  

       </c:otherwise>

</c:choose>

 

           <c:forEach>   </c:forEach>

 

//      

<c:forEach items="${finalResult.rows}" var="row">       

<tr class="<%=tdClass[(rank+1)%2]%>">

<td align="center"><span><%=rank%> </span></td>

<td align="center"><span ><c:out value="${row.player_name}"/></span> </td>

<td align="center"><span > ¥ <c:out value="${row.money}"/></span></td>

</tr>

<%rank++;%>     

</c:forEach> 

 

         。

<c:forEach var =”i” begin=”100 “ end= “110”>

       ${i}

</c:forEach>

      step= “ 2 ”        2 。

 

 . sql   

 

     :

<sql:setDataSource dataSource="proxool.breadTycoon" />

//                  

<sql:query var="finalResult" >

    select player_name,money from tb_player order by money DESC LIMIT 10   

</sql:query>

           :

  <c:forEach items="${ finalResult.rows}" var="row" varStatus="s">

        advCosts[${s.index}]=${row.adv_cost};

   </c:forEach>

             :

<sql:update>  

                call proc_set_role_salespro(?,?,?,?,?);

                <sql:param value="30"/>

                <sql:param value="39"/>

                <sql:param value="<%=spID%>"/>

                <sql:param value="<%=productID%>"/>

                <sql:param value="1"/>               

            </sql:update>

 

<sql:query var="queryAllChannelCount">

SELECT COUNT(*) as total FROM tb_channel WHERE game_id=? AND begin_round<func_cur_round(?) AND player_id=? AND channel_flag=0

<sql:param value="${gameID}"/>

<sql:param value="${gameID}"/>

<sql:param value="${playerID}"/>

</sql:query>

<c:forEach items="${queryAllChannelCount.rowsByIndex}" var="channelCN">

       <c:set value="${channelCN[0]}" var="channelTotal"/>

</c:forEach>

 

           :

 

<c:if test="${param.changsubmit!=null}" >

<c:forEach items="${paramValues.pro_id}" var="getpro_id" varStatus="getparamsta">

<sql:update>

 

call proc_set_role_product(?,?,?,?,?,?,?,?);

 

<sql:param value="${gameID}"/>

<sql:param value="${playerID}"/>

<sql:param value="${getpro_id}"/>

<sql:param value="${getpro_id}"/>

<sql:param value="${paramValues.pro_sort[getparamsta.index]}"/>

<sql:param value="${paramValues.price[getparamsta.index]}"/>

<sql:param value="${paramValues.output[getparamsta.index]}"/>

<sql:param value="0"/>

</sql:update>

</c:forEach>

</c:if>

 .      

 

<fmt: formatNumber value =”12.3” pattern=”.000”/>

    12.300.      ”.000”,              3  。   3     0   。

 

       <fmt:formatDate value=”<%=new java.util.Date() %>” type=”date” />

              : 2007-5-27 .

<fmt:formatDate value=”<%=new java.util.Date() %>” type=”time” />

       : 9:25:11

<fmt:formatDate value=”<%=new java.util.Date() %>” type=”both” />

       : 2007-5-27 9:25:11

 

 

 

     :

 

1.    request.getParameter("test"):

<c:if test="${param.test!=null}" >

<c:out value="${param.test}" />

</c:if>

 

2. <c:redirect url="a.jsp">

 

3.<c:redirect url="/max.jsp" context="/ch16">

<c:param name="name1" value="665"/>

<c:param name="name3" value="     "/>

</c:redirect>

 

4.<c:forTokens items="zhangsan:lisi:as" delims=":" var="name">

${name}

</c:forTokens>