C标签和S标签

来源:互联网 发布:java判断上传文件类型 编辑:程序博客网 时间:2024/06/05 09:49

SpringMVC 自带标签没有Struts2的好用。。。

    

1.使用s:if判断字符串 
Java代码  
  1. <s:if test="name!='doom'">  
  2.        ..... 
  3. </s:if>  
  4. <s:else>
  5.     .... 
  6. </s:else>



2.s:if判断null 

Java代码  收藏代码
  1. <s:if test="list!=null && list.size!=0">  
  2.     <table border="1">  
  3.         <tr><td>table1</td><tr>  
  4.             <s:iterator value="list" id="u" status="st">  
  5.                 <tr>  
  6.                     <td><s:property value="#st.index" /></td>  
  7.                     <td> <s:property value="[color=red]#u.id[/color]"/></td>  
  8.                     <td> <s:property value="[color=red]username[/color]"/></td>  
  9.                     <td> <s:property value="password"/></td>  
  10.                 <tr>  
  11.             </s:iterator>  
  12.     </table>  
  13.     </s:if>  


3.c:if判断是否为null 
Java代码  收藏代码
  1. <c:if test="${!empty list}"
  2.  <table border="1">  
  3.     <tr><td colspan="3">table2</td><tr>  
  4.     <c:forEach var="u" items="${list}" varStatus="sta">  
  5.                 <tr>  
  6.                    <td>${sta.index}</td>  
  7.                    <td align="center"> ${u.id} </td>  
  8.                    <td align="center"> ${u.username } </td>  
  9.                    <td align="center"> ${u.password} </td>  
  10.                 </tr>  
  11.     </c:forEach>  
  12.     </table>  
  13.    </c:if>  



4.c:标签没有 else标签  可以通过 c:choose   c:when  c:otherwise实现 
Java代码  收藏代码
  1.                <tr>
            <td>学历</td>
            <td>
                    <select name="education">
                    <c:if test="${employ.education==null }">
                     <option value="" selected="selected">请选择</option>
                    </c:if>
                     <c:choose>
                     <c:when test="${employ.education=='高中'}">
             <option value="高中" selected="selected">高中</option>
            </c:when>
            <c:otherwise>
            <option value="高中">高中</option>
            </c:otherwise>
            </c:choose>
                    <c:choose>
                     <c:when test="${employ.education=='大专'}">
             <option value="大专" selected="selected">大专</option>
            </c:when>
            <c:otherwise>
            <option value="大专">大专</option>
            </c:otherwise>
            </c:choose>
             <c:choose>
                     <c:when test="${employ.education=='本科'}">
             <option value="本科" selected="selected">本科</option>
            </c:when>
            <c:otherwise>
            <option value="本科">本科</option>
            </c:otherwise>
            </c:choose>
             <c:choose>
                     <c:when test="${employ.education=='研究生'}">
             <option value="研究生" selected="selected">研究生</option>
            </c:when>
            <c:otherwise>
            <option value="研究生">研究生</option>
            </c:otherwise>
            </c:choose>
             <c:choose>
                     <c:when test="${employ.education=='博士'}">
             <option value="博士" selected="selected">博士</option>
            </c:when>
            <c:otherwise>
            <option value="博士">博士</option>
            </c:otherwise>
            </c:choose>        
           </select>     
      </td> 
     </tr>

0 0
原创粉丝点击