JSP第三天

來源:互聯網
上載者:User

el運算式語言的作用:
 擷取資料並顯示
 參數
  ${param.參數名}
  ${paramValues.參數名[i]}
 屬性
  ${**Scope.屬性名稱}
  ${屬性名稱}
   request-->session-->application
 擷取request對象
  ${pageContext.request.contextPath}
邏輯分支控制語句:
 JSTL:java standard tag libarary     java標準標籤庫
 html中嵌入java代碼,<起始標籤 屬性名稱="屬性值">標籤體</結束標籤>

 <首碼:center>hehe</首碼:center>

JSTL標籤具有的內容:
 1 約束標籤書寫規則的文檔:
 tld檔案--tag libarary defination標籤庫的定義檔案
 2 標籤處理類,提供標籤所具有的功能

JSTL的標籤分類:
 c:  core核心標籤庫
 sql:訪問操作資料庫的標籤庫 
 x:  操作xml檔案的標籤庫
 fmt:格式化顯示資訊、國際化的標籤庫

tld檔案的內容:
 <description>JSTL 1.1 core library</description> 標籤庫描述資訊
   <display-name>JSTL core</display-name>
   <tlib-version>1.1</tlib-version>
   <short-name>c</short-name>    統一首碼
   <uri>http://java.sun.com/jsp/jstl/core</uri>  標示當前標籤庫唯一的邏輯地址

  <tag>           一組標籤定義
    <description>
        Catches any Throwable that occurs in its body and optionally   描述當前標籤的作用
        exposes it.
    </description>
    <name>catch</name>         標籤名
    <tag-class>org.apache.taglibs.standard.tag.common.core.CatchTag</tag-class>  當前標籤對應的處理類
    <body-content>JSP</body-content>       標籤體的內容類型  
    <attribute>          標籤的屬性
        <description>         標籤屬性的功能描述
Name of the exported scoped variable for the
exception thrown from a nested action. The type of the
scoped variable is the type of the exception thrown.
        </description>
        <name>var</name>        屬性名稱
        <required>false</required>       定義當前屬性是否必須存在  
        <rtexprvalue>false</rtexprvalue>      當前屬性的值是否支援el運算式
 <type>...         屬性值的類型,預設是string
    </attribute>
  </tag>

jsp:
 html  負責顯示
 javaScript 負責用戶端的格式化校正
 jstl  負責邏輯分支語句
 el  負責擷取資料並顯示

c標籤庫:
 *1 <c:if test="1>2">hehe</c:if>
 ===>
 if(1>2){
  <%="hehe"%>
 }
 
 <c:if test="${1 gt 2 }" var="flag" scope="request">
  hehe
 </c:if>
 ==>
 var flag = ${1 gt 2 };
 request.setAttribute("flag",flag);
 if(flag){
  <%="hehe"%>
 }

 *2
 <c:choose>
  <c:when test="${param.age < 20}">
   小孩兒~!
  </c:when>
  <c:when test="${param.age >= 20 && param.age < 40}">
   青年人
  </c:when>
  <c:otherwise>
   老啦~!
  </c:otherwise>
 </c:choose>
 ==>
 switch(..){
  case ..:
  case ..:
  ..
  default:
 }
 *3
 <c:for
 ==>
 int count = request.getParameter("count"); 
 int info= request.getParameter("info");
 for(int i = 1 ; i < count ; i++){
  <%=info%>
 }

 <c:forEach items="${strs}" var="entry">
  ${entry.key } === ${entry.value }<br>
 </c:forEach>
 ==>
 Map strs = ${strs};
 Set<Map.Entry> entrys = strs.entrySet();
 for(Map.Entry entry : entrys){
  entry.getKey();
  entry.getValue();
 }

 4 <c:set scope="request" value="123" var="as"></c:set>
 ==》
 request.setAttibute("as",123);

 5 <c:remove var="as"/>
 ==>
 【pageContext.remove("as",PageScope.REQUEST_SCOPE)】
 pageContext.remove("as");
  將當前jsp頁面所在的web應用中所有名為as的屬性全部移除
 6
 <c:redirect url="../../../stuMgmt"></c:redirect>
 ==》
 response.sendRedirect可以跨應用跳轉
 注意:
  <c:redirect>中的絕對路徑,起始點為【/應用程式名稱】

 7 <c:import url="for.jsp"></c:import>
 ==>
 <jsp:include page="for.jsp"/>
 
 
 i18n:
  internationalization國際化

  1 提供多個不同語言的資源檔
   resourse_zh.properties
    name=張三
   resourse_es.properties
    name=zhangsan

  2 提供一個類,先擷取當前系統所支援的語言格式zh,動態尋找其對應的資源檔_zh
    提供一個方法,根據統一的某一個key尋找對應值
 
  3 jsp中調用上述類的方法,動態擷取具體顯示的資訊
   

 

 dom解析:
  1 DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
  2 DocumentBuilder b = f.newDoucmentBuilder();
  3 Document doc = b.parse("");
  4 Element root = doc.getDocumentElement();
  5 NodeList ns = root.getElementsByTagName("");
    for(int i = 0 ; i < ns.getLength(); i++){
   Element e = (Element)ns.item(i);
   ....
   
          }/
  ns.item(0).getFirstChild().getNodeValue();
   
 doc/games/country/athlete

java_home=...
path=%java_home%/bin

set NLS_LANG=SIMPLIFIED CHINESE_CHINA.ZHS16GBK
set NLS_LANG=AMERICAN_AMERICA.USACII7

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.