JSP中一些需要注意和經常忘記的問題

1、如何使用jstl判斷集合是否爲空
 ${user}爲集合,user爲集合名
 <c:if test="${empty user}">無信息!</c:if>爲空

 <c:if test="${!empty user}">其它</c:if>非空

2、jstl中的數字格式化輸出;
   <fmt:formatNumber  value="${n}" pattern="###,###.0000" />

3、jstl格式化百分數:
 <fmt:formatNumber value="${scale1}" type="percent" pattern=".00%"></fmt:formatNumber>


4、Java格式化百分數:
 DecimalFormat df = new DecimalFormat("##.00%");
 return df.format(percent); 

5、在js中添加鏈接地址,鏈接到服務器:
  window.location.href:後面接完整的URL地址;


6、jsp使用EL表達式獲取當前web應用的名稱
  ${ pageContext.request.contextPath }

7、標籤用法
  <c:choose> 
   <c:when test="${empty param.username}">   
    Nnknown user.  
   </c:when> 
   <c:when test="${param.username=='Tom'}">   
    ${param.username} is manager.  
   </c:when> 
   <c:otherwise>   
    ${param.username} is employee.  
   </c:otherwise> 
  </c:choose>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章