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