`
spde1988
  • 浏览: 1371 次
  • 性别: Icon_minigender_1
  • 来自: 江西
最近访客 更多访客>>
文章分类
社区版块
存档分类
最新评论

jstl总结

阅读更多
以下是我的对Jstl的总结。这些代码包含的jstl的主要语法。
1.<%@ taglib uri='http://java.sun.com/jstl/core' prefix='c' %>
2.The pageContext implicit object lets you access the page context, which has references to the request, response, session, servlet context, servlet config, etc
<c:out value='${param.name}'/>
<c:forEach items='${initParam}' var='parameter'>
   <ul>
      <%-- Display the key of the current item, which
           corresponds to the name of the init param --%>
      <li>Name: <c:out value='${parameter.key}'/></li>
      <%-- Display the value of the current item, which
           corresponds to the value of the init param --%>
      <li>Value: <c:out value='${parameter.value}'/></li>
   </ul>
</c:forEach>
3.<c:if test='${not empty param.amount}'>
   <c:out value='${param.amount}'/>
</c:if>
4.There's a lot more to the Core library than evaluating expressions and displaying the result; for example, you can implement if/then statements and switch constructs.
<c:choose>
         <c:when test='${not empty param.name}'>
            Hello <c:out value='${param.name}'/>.
         </c:when>
         <c:otherwise>
            <font color='red'>
               Please enter your name:<p>
            </font>
          <jsp:include page='index.jsp'/>
         </c:otherwise>
      </c:choose> '
5.<fmt:setLocale value='en-US'/>
<jsp:useBean id='today' class='java.util.Date'/>
<fmt:formatDate value='${today}' type='both'/>
6.<sql:transaction>
   <%-- Withdraw money from the "from" customer's account --%>
   <sql:update>
      UPDATE ACCOUNTS SET BALANCE = BALANCE - ?  WHERE CUST_ID = ?
      <sql:param value='${param.amount}'/>
      <sql:param value='${param.fromCustomer}'/>
   </sql:update>
</sql:transaction>'
7.<c:out value='${param.amount}'/>
<c:forEach var='item' items='${names}' varStatus='status'>
The var and scope Attributes
<fmt:message key='index.greeting' var='msg' scope='request'/>
8.The expression language provides:
Expressions and identifiers
Arithmetic, logical, and relational operators
Automatic type coercion  && (and) || (or) ! (not) empty
Access to beans, arrays, lists, and maps
Access to a set of implicit objects and servlet properties
9.<% // Create a string
   String s = "Richard Wilson";
   // Store the string in page scope
   pageContext.setAttribute("name", s); %>
<%-- Access the string with an EL expression --%>
<c:out value='${name}'/>
10. if you have a Name bean stored in a scoped variable named name and that bean contains firstName and lastName properties, you can access those properties like this:
First Name: <c:out value='${name.firstName}'/>
First Name: <c:out value='${name["firstName"]}'/>
11.public class UserProfile {
   private Name name;
   private Address address;
}
<c:out value='${pageScope.profile.name.lastName}'/>:
10.Accessing Objects Stored in Arrays, Lists, and Maps
      HashMap         profileMap = new HashMap();
      LinkedList     profileList = new LinkedList();
JavaBean Component   ${colorBean.red}
Array  ${colorArray[2]}    Array.get(colorArray, 2)
List  colorList[2]  colorList["2"]   colorList.get(2)
Map  colorMap[red]  colorMap.get(pageContext.findAttribute("red"))
colorMap.get("red")
<select name='headerName'>
            <c:forEach var='hdr' items='${header}'>
               <option value='<c:out value="${hdr.key}"/>'>
                  <c:out value='${hdr.key}'/>
               </option>
            </c:forEach>
         </select>
11.<c:choose>
         <c:when test='${param.scope == "page"}'>
            <c:set var='scope' value='${pageScope}'/>
         </c:when>
</c:choose>
12.<c:forEach var='item' items='${listWrapper.list}'>
            <li><c:out value='${item}'/></li>
         </c:forEach>
13<c:forTokens items='ONE | TWO | THREE | FOUR'
            delims='|' var='item'>
   <c:out value='${item}'/>
</c:forTokens>
14 current Object The current item in the iteration
15.<%-- Set the locale for <fmt:message> actions to zh
          (Chinese) --%>
      <fmt:setLocale value='zh'/>
<c:out value='${pageContext.request.characterEncoding}'/>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics