JSTL常用语法

el表达式的取值默认顺序:
    pageScope  requestScope  sessionScope  applicationScope
   
结构,采用.导航,也称为存取器   ${user.name}  ${user.class.name}
                      输出map   ${mapValue.key1}
                     输出数组   ${strArray[1]}
                     输出list   ${list[1].name}
                    
el表达式的运算 
               ${1+2}=       3
               ${10/5}=      2.0
               ${10%3}=      1
               ${10 div 2}=  5.0
               ${10 mod 4}=  2
              
el表达式对应的运算符
                     等于  ==    eq
                   不等于  !=    ne
                     大于  >     gt
                     小于  <     lt
                 大于等于  >=    ge
                 小于等于  <=    le
                       与  &&    or
                       或  ||    and
                       非  !     not
                       加  +
                       减  -
                       乘  *
                     除以  /     div
                     求莫  %     mod
                    
el表达式判断是否为空
                    request.setAttribute("value1",null)                    ${empty requestScope.value1} = true
                    request.setAttribute("value2","")                      ${empty requestScope.value1} = true
                    request.setAttribute("value3",new ArrayList())         ${empty requestScope.value1} = true
                    request.setAttribute("value4","i love you")            ${empty requestScope.value1} = false
                    request.setAttribute("value4","i love you")            ${!empty requestScope.value1} = true
                   
-------------------------------------------------------------------------
web.xml的
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.4">  大于等于2.4 方可支持jstl
先引入 standard.jar 和 jstl.jar
jstl标签的用法  在页面引入  <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

    输出标签 -----------
                 <c:out value="ppp" />                                              输出   ppp
                 <c:out value="null" default="ddd"/>                                输出   ddd   可以设置默认值
                 <c:out value="<font color="red">kkk</font>" escapeXml="false"/>    输出 红色的kkk    默认的escapeXml为true
    赋值标签 -----------    
                 <c:set value="123" var="jj" scope="session" />       此时有个名为jj,值为123的session ,默认的scope为page
                                                          ${jj}       在页面打印出123
                 <c:remove var="jj" />                                将其删除,可以指定scope,默认为page      
    逻辑标签 -----------
                 <c:if test="?" />                                   ?:代表条件 可以用el表达式     
             -----------
                 <c:choose>
                     <c:when test="?">
                        ......                                         相当于 if...else...   c:when 可以有多个,相当于else if
                     </c:when>
                     <otherwise>
                       ......
                     </otherwise>
                 </choose>
循环控制标签 -----------
                 <c:forEach items="${list}" var="u" >                   ${list}是一个集合
                     ${u.name}
                 </c:forEach>
                
                
                 <c:forEach items="${list}" var="u" varStatu="ss">                 
                     <c:choose>
                     <c:when test="u.age % 2 == 0">
                        <tr bgColor="red">                                  如果集合中的数字是偶数,则当行为红色
                     </c:when>
                     <otherwise>
                        <tr>   
                     </otherwise>
                     </choose>
                 </c:forEach>
                
                
                 <c:forEach items="${list}" var="u" begin="2" end="8" step="2">                 输出下表(从0开始)为2到8的元素,每次递增2
                     ${u.name}                                                                  将输出u[2].name  u[4].name  u[6].name  u[8].name
                 </c:forEach>
                                  
                 Map m = new Map();
                 m.put("k1","v1");        
                 m.put("k2","v2");        
                 request.setAttribute("mapValue",m);
                
                 <c:forEach items="mapValue" var="ma">
                     ${ma.key} = ${ma.value}                                 输出:  k1=v1  k2=v2  
                 </c:forEach>
                
   间隔符控制标签-------------
           
                    request.setAttribute("str","1,2,3,4,5");     
                   
                    <c:forTokens items="str" delims="," var="de">            
                        ${de}                                                  输出 12345
                    </c:forTokens>    
                   
   捕获异常标签  ----------
          
                   <c:catch var="info">
                       <%
                         Integer.parseInt("sdfsdf");                
                       %>       
                   </c:catch>
                  
                   ${info}                                             输出:异常信息
                  
   导入页面标签 -----------
       
                   <c:import url="http://www.baidu.com" />            相当于include
                  
   链接标签    ------------
   
                   <c:url value="http://www.baidu.com" var="v"/>
                       <c:param name="name" value="jack" />
                       <c:param name="age" value="20" />
                   </url>    
                  
                   ${v}              输出        http://www.baidu.com?name=jack&age=20
                  
    重定向标签 ------------
       
                   <c:redirect context="/company" url="/index.jsp">   定位到名叫company的项目下的index.jsp页面 

你可能感兴趣的:(C++,c,Web,jsp,C#)