天天看點

張孝祥老師編寫的EL函數标簽庫第8章 标準标簽庫(JSTL)

绗?8绔? ??????绛懼?(JSTL)

8.1??澶?瀹?楠???澧?

??绔?涓???????渚?瀛?绋?搴??藉?ㄥ??涓?STL??WEB搴??ㄧ?搴?涓?杩?琛?锛?浣跨?ㄧ??Tomcat???″?ㄧ????涓?omcat5.5??涓轟?绠???浠g????绐??洪???癸???绔?涓???????JSP缃?椤墊??浠剁??渚?瀛?绋?搴??界???ヤ?<html>??<head>??<title>??<body>绛?HTML?ㄥ??舵????绛俱????绔?涓??ㄤ???杩版??绛劇??璇?娉?????绉?绗??風????涔?濡?涓?锛?

l?[??锛?琛ㄧず?規???蜂腑????瀹規????????锛?

l?{option1|option2|option3|??锛?琛ㄧず?辨???蜂腑?ㄢ??|??瀛?绗?????????涓???椤逛??藉???跺?虹?幫????藉?虹?闆?朵腑??涓?椤癸?

l?濡???灞??х???煎??浣???绮?锛?琛ㄧず杩?涓??兼??瀵瑰?灞??х??榛?璁ゅ?鹼?

濡???灞??х???肩?ㄦ??浣?瀛?琛ㄧず锛?琛ㄧず璇ュ??у??浠ユ??琛ㄨ揪寮?锛?濡?????绛句?????瀹圭?ㄦ??浣?瀛?琛ㄧず锛?琛ㄧず??绛句?????瀹瑰??浠ユ??JSP浠g????

涓轟???绔????㈣?茶В???逛究锛?杩???????寤轟?涓???涓?serBean??JavaBean绋?搴?锛?濡?渚?绋?8-1??绀恒??

渚?绋? 8-1? UserBean.java

?

package org.it315;

public class UserBean

{

??? private StringuserName;

??? private String password;

??? private Stringaddress;

??? private intvisitCount;

??? public voidsetUserName(String userName)

??? {

??????? this.userName= userName;

??? }

??? public StringgetUserName()

??? {

??????? returnuserName;

??? }

??? public void setPassword(Stringpassword)

??? {

??????? this.password= password;

??? }

??? public String getPassword()

??? {

??????? return password;

??? }

??? public voidsetAddress(String address)

??? {

??????? this.address =address;

??? }

??? public StringgetAddress()

??? {

??????? returnaddress;

??? }

??? public voidsetVisitCount(int visitCount)

??? {

??????? this.visitCount= visitCount;

??? }

??? public intgetVisitCount()

??? {

??????? returnvisitCount;

??? }

}

?

缂?璇?杩?涓?婧?绋?搴?锛?灏?缂?璇?????UserBean.class??浠舵?懼??lt;TOMCAT_HOME>\webapps\JSTL\WEB-INF\classes\org\it315??褰?涓???

8.2? JSTL姒?杩?/h2>

8.2.1 ?JSTL绠?浠?

浠?JSP 1.1瑙???寮?濮?JSP灏辨????浣跨?ㄨ??瀹?涔???绛撅?浣跨?ㄨ??瀹?涔???绛懼ぇ澶ч??浣?浜?JSP椤甸?㈢??澶???搴?????跺?寮轟?浠g???????ㄦ?э???姝よ??瀹?涔???绛懼??EB搴??ㄤ腑琚?骞挎?浣跨?ㄣ??璁稿?WEB搴??ㄥ?????藉????轟???宸辯??涓?濂???绛懼???渚?缁??ㄦ?蜂嬌???杩?瀵艱?村?虹?頒?璁稿????界?稿??????绛撅?浠ょ?椤靛?朵?????????浠?锛?涓??ラ?????╁??涓?瀹剁??濂姐??涓轟?瑙e?寵?涓???棰?锛?Apache Jakarta灏?缁?褰?绾蟲??諱??d?缃?椤佃?捐?′漢??缁?甯擱???扮????棰?锛?寮???浜?涓?濂??ㄤ?瑙e?寵?浜?甯哥?ㄩ??棰?????瀹?涔???绛懼?锛?杩?濂???绛懼?琚?SUN???稿??涔?涓烘??????绛懼?锛?The JavaServer Pages StandardTag Library锛?锛?绠?绉?STL??浣跨??STL??浠ヨВ?崇?ㄦ?烽???ㄤ???WEB????????瀹?涔???绛炬?剁???版??锛?JSP瑙??????朵???璁?EB瀹瑰?ㄥ??????JSTL??绛懼?????????渚???宸辯??瀹??幫?浠ヨ?峰????浣蟲?ц?姐??

?變?JSTL????SP 1.2瑙???涓?瀹?涔???锛???浠?STL??瑕?杩?琛??ㄦ????JSP 1.2???舵?撮????????WEB瀹瑰?ㄤ?锛?渚?濡?锛?Tomcat 5.5??

1锛?JSTL???昏?缁???

绗????ㄥ????绔???瀹規?剁??JSTL瑙????????扮??????JSTL 1.1锛?瀹???JSP 2.0???拌???涓???涓?涓???瑕?缁????ㄥ????JSTL 1.1涓???????涓???绛懼???涓?缁?EL?芥?般??涓烘?逛究?ㄦ?蜂嬌???JSP瑙???涓???杩頒?JSTL????涓???绛懼???URI?闆????寤鴻??浣跨?ㄧ????缂???锛?濡?琛?.1??绀恒????绔?涓??ㄤ嬌??STL??绛炬?訛?浣跨?ㄧ???芥??杩?浜?寤鴻??????缂???

?

琛?.1? JSTL

??绛懼????芥??杩? ??绛懼???URI 寤鴻????缂?
?稿???绛懼? http://java.sun.com/jsp/jstl/core c
XML??绛懼? http://java.sun.com/jsp/jstl/xml x
?介????/?煎?????绛懼? http://java.sun.com/jsp/jstl/fmt fmt
?版??搴???绛懼? http://java.sun.com/jsp/jstl/sql sql
EL??瀹?涔??芥?? http://java.sun.com/jsp/jstl/functions fn

?

涓??㈠??STL????涓???绛懼?杩?琛?绠?????浠?缁?锛?

锛?1锛??稿???绛懼?涓?????浜?瀹???EB搴??ㄤ腑?????ㄦ??浣?????绛俱??渚?濡?锛??ㄤ?杈??轟?涓???????瀹圭??<c:out>??绛俱???ㄤ??′歡?ゆ????<c:if>??绛俱???ㄤ?杩?浠e驚????<c:forEach>??绛俱??

锛?2锛??介????/?煎?????绛懼?涓?????瀹???EB搴??ㄧ?搴????介????????绛俱??渚?濡?锛?璁劇疆JSP椤甸?㈢?????頒俊????璁劇疆JSP椤甸?㈢???跺?恒??缁?瀹?璧?婧???浠訛?浣挎???版???????版??锛?渚?濡??闆?箋???ユ??绛?锛?????SP椤甸??腑璁劇疆?????版?煎??劇ず??

锛?3锛??版??搴???绛懼?涓??????ㄤ?璁塊???版??搴???瀵規?版??搴?涓????版??杩?琛???浣?????绛俱??渚?濡?锛?浠??版??婧?涓??峰??版??搴?杩??ャ??浠??版??搴?琛ㄤ腑妫?绱㈡?版??绛????變??ㄨ蔣浠跺??灞???寮???妯″??涓?锛?JSP椤甸????ㄤ?琛ㄧ?闆?锛???浠?涓???涓???SP椤甸??腑?存?ユ??浣??版??搴?锛??????ㄤ??¢?昏?灞????版??璁塊??灞???浣??版??搴?锛???浠ワ?JSTL涓???渚???杩?濂??版??搴???绛懼?娌℃??澶?澶х??瀹??ㄤ環?箋??

锛?4锛?XML??绛懼?涓?????瀵?ML??妗d腑???版??杩?琛???浣?????绛俱??渚?濡?锛?瑙f??XML??妗c??杈???ML??妗d腑????瀹癸?浠ュ??杩?浠e???XML??妗d腑????绱?????涓?ML骞挎?搴??ㄤ?WEB寮???锛?瀵?ML??妗g??澶?????甯擱??瑕?锛?XML??绛懼?浣垮???XML??妗e??寰?绠????逛究锛?杩?涔???JSTL??涓?涓???瑕??瑰????

锛?5锛?JSTL涓???渚???涓?濂?EL??瀹?涔??芥?闆????浜?JSP椤甸?㈠?朵???缁?甯歌??ㄥ?扮??瀛?绗?覆??浣???渚?濡?锛?????瀛?绗?覆涓???瀛?瀛?绗?覆???峰??瀛?绗?覆???垮害??澶???瀛?绗?覆涓???绌烘?肩????

2锛?JSTL???╃??缁???

瀹??寸??JSTL搴?????SUN???告??渚???jstl.jar ????WEB瀹瑰?ㄤ駭????渚???JSTL瀹??闆??锛?浠?pache Jakarta 灏?缁???渚???JSTL瀹??闆??涓轟?锛?瀹??寸??JSTL????jstl.jar??standard.jar ?? xalan.jar 涓?涓? jar ????sun???告??渚???jstl.jar ??灏?瑁?浜? JSTL??瑕?姹???涓?浜?API ?ュ?e??绫夥?Apache Jakarta 灏?缁?缂????? JSTL API 瀹??扮被灏?瑁???tandard.jar??涓????變? JDK ??JDK 1.5 ????涓???寮??ヤ? XPath API锛??? apache Jakarta 灏?缁?寮????? JSTL API ????DK1.5 涔????ㄥ?虹??锛???浠?apache Jakarta 灏?缁???JSTL 涓?浣跨?ㄧ????浠?浠???宸卞????? XPath API锛?杩?浜? API 灏?瑁???xalan.jar ??涓???Standard.jar??涓??????稿???绛懼????介????/?煎?????绛懼????版??搴???绛懼?涓?????绛懼????????EL??瀹?涔??芥?扮??瀹??扮被锛?xalan.jar ??涓????? JSTL 瑙f?? XPath ???稿??API 绫彙??

8.2.2 ?瀹?瑁???娴?璇?JSTL

1锛?涓?杞?STL??

??浠ヤ?Apache??缃?绔?涓?杞?STL??jar????杩???ttp://jakarta.apache.org/taglibs/ 椤甸????規???稿?崇????绀轟俊??涓?杞?zip??缂╂??浠訛?杩?涓???缂╂??浠朵腑????JSTL??涓?涓?jar????

??绀猴??變?缃?绔???涓?????绾э?涓?杞?STL ??jar????缃??????芥?瑰????璇昏???ㄤ?杞借?浜???浠舵?訛?濡????ㄦ??瀹???缃???娌℃??涓?杞界???炬?ワ???浠ヨ???pache??缃?绔?棣?椤碉??跺???規???稿?崇????绀轟?杞芥????????浠躲??渚?濡?锛?绗????ㄧ???JSTL??绋挎?訛?浠?http://jakarta.apache.org/taglibs/涓?杞界????缂╂??浠朵腑??????jstl.jar??standard.jar涓や釜jar ??锛??? xalan.jar??瑕?浠? http://xml.apache.org/xalan-j/downloads.html涓?杞姐??

2锛?瀹?瑁?JSTL

??omcat涓?瀹?瑁?JSTL寰?绠???锛???瑕?灏? JSTL??jar??澶??跺??lt;WEB搴??ㄧ?搴?>\WEB-INF\lib??褰?涓??沖??????绔?涓???????渚?瀛?绋?搴??藉?ㄤ?涓???涓?STL??WEB搴??ㄧ?搴?涓?杩?琛?锛???浠ワ?灏?JSTL??涓?涓?jar??澶??跺??<TOMCAT_HOME>\webapps\JSTL\WEB-INF\lib??褰?涓??沖????浜?JSTL??瀹?瑁???

??绀猴?Tomcat 5.5??甯???JSP渚?瀛?搴??ㄧ?搴?涓???渚?浜?浣跨??STL??绛劇??渚?瀛?锛???lt;TOMCAT_HOME>\webapps\jsp-examples\WEB-INF\lib??褰?涓???JSTL??jstl.jar????standard.jar??锛???浠ワ?瀵逛?璇昏???ヨ?達?濡???涓?浣跨??STL??XML??绛懼?涓?????绛撅???浠ョ?存?ュ?杩?涓や釜??澶??跺??lt;WEB搴??ㄧ?搴???涓葷??褰?>\WEB-INF\lib??褰?涓?锛???涓??ㄤ???浠?Apache??缃?绔?涓?杞?STL??jar????

3锛?娴?璇?JSTL

瀹?瑁?瀹?JSTL??锛??ヤ??ュ氨??浠ュ??澶?娴?璇?JSTL瀹?瑁?寰?????????浜???

Apache灏?缁??ㄦ??渚?JSTL?訛????朵???渚?浜?JSTL??绛劇????绛炬??杩版??浠訛???LD??浠訛?锛?瀹?浠??藉?瑁???tandard.jar??涓?锛?浣?浜?璇?ar??浠剁??META-INF??褰?涓?????inRAR ??寮?standard.jar??锛?杩???ETA-INF??褰?锛???浠ョ????STL??绛劇????绛懼???杩版??浠躲???ョ??杩?浜?TLD婧???浠訛???浠ョ???版??浠朵腑瀹?涔???<uri> ??绱?????瀹逛?琛?.1涓????虹????绛懼???URI?稿??????涓?tandard.jar ??涓?灏?瑁?浜?JSTL??绛劇????绛懼???杩版??浠訛?Tomcat?ㄥ???ㄦ?朵????ㄥ??杞?tandard.jar??涓???META-INF??褰?涓???????TLD??浠訛???浠ヤ嬌??STL?朵?蹇???eb.xml??浠朵腑??缃?JSTL??绛懼???URI淇℃??锛?灏卞??浠ュ??SP??浠朵腑?存?ヤ嬌??STL??绛俱??

瑕???SP??浠朵腑浣跨??STL锛?棣???灏遍??瑕?浣跨??aglib??浠ゅ?煎?ユ????瑕?浣跨?ㄧ??JSTL??绛懼?锛?taglib??浠ょ??uri灞??у?椤諱負?稿???绛懼???TLD??浠朵腑??<uri>??绱????鹼?taglib??浠ょ??prefix灞??у??浠ヨ??宸遍??????瀹?锛?浣???濂芥?????ㄨ〃8.1涓???寤鴻????缂?????STL搴??ㄧ?搴???涓葷??褰?涓???渚?绋?8-2缂???涓?涓?????JSTL??绛劇??绠???JSP??浠?est.jsp??

渚?绋?8-2 test.jsp

?

<%@ tagliburi="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<c:out value="hello world!"/>

?

涓??㈢??test.jsp椤甸??腑??<c:out>??绛劇?ㄤ???娴?瑙??ㄨ??烘??????瀹癸?瀹?灞?浜?JSTL???稿???绛懼?涓?????绛俱???變???est.jsp??浠朵腑??浣跨?ㄤ?JSTL???稿???绛懼?涓?????绛撅???浠ワ?????瑕?浣跨?ㄤ???aglib??浠ゅ?煎??STL???稿???绛懼?锛???涓?蹇?浣跨?ㄥ???aglib??浠ゅ?煎??STL????????绛懼???

????omcat??锛??ㄦ?瑙??ㄥ?闆????涓?杈???est.jsp椤甸?㈢???闆??杩?琛?璁塊??锛?濡???娴?瑙??ㄤ腑?劇ず?轟???hello world!??锛?璇存??JSTL瀹?瑁???????

8.3 ??稿???绛懼?

JSTL?稿???绛懼?????浜?涓?缁??ㄤ?瀹???EB搴??ㄤ腑?????ㄦ??浣?????绛撅?JSP瑙???涓烘?稿???绛懼?寤鴻??????缂???涓???

8.3.1 ?<c:out>??绛?/h3>

<c:out> ??绛劇?ㄤ?杈??轟?娈墊??????瀹瑰??ageContext瀵矽薄褰???淇?瀛?????out??瀵矽薄涓?锛??ㄩ??甯告???典?锛?pageContext瀵矽薄褰???淇?瀛?????out??瀵矽薄???版????杈??哄?闆?㈡?風??娴?瑙??????浠ワ?<c:out> ??绛鵑??甯哥?ㄤ?杈??轟?娈墊??????瀹瑰?闆?㈡?風??娴?瑙??ㄣ??濡???<c:out>??绛捐??虹????????瀹逛腑????浜???瑕?杩?琛?杞?涔???HTML?規??瀛?绗??渚?濡?锛?<??>??'??"??&绛?锛?<c:out> ??绛鵑?璁ゅ?瑰??浠???琛?.2杩?琛?HTML缂???杞??㈠????杩?琛?杈??猴?杩??峰氨??浠ュ?ㄦ?瑙??ㄤ腑?劇ず?鴻?浜?瀛?绗???

琛?.2 ?規??瀛?绗?漿??

<c:out>??绛炬??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<c:out value="value"

??? [escapeXml="{true|false}"]

?? [default="defaultValue"]/>

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹?杈??虹??榛?璁ゅ?鹼?

<c:outvalue="value"

?? [escapeXml="{true|false}"] >

defaultvalue

</c:out>

<c:out>??绛劇??灞??ц?存??濡?琛?.3??绀恒??

琛?.3? <c:out>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true Object ??瀹?瑕?杈??虹????瀹?
escapeXml true Boolean ??瀹??????>??<??&??'??" 绛??規??瀛?绗??琛?HTML缂???杞??㈠????杩?琛?杈??恒??榛?璁ゅ?間負true
default true Object ??瀹?濡???value灞??х???間負null?舵??杈??虹??榛?璁ゅ??

?

褰?涓?浠?褰?value灞??х???間負null?訛?<c:out> ??绛捐??洪?璁ゅ?鹼?濡???娌℃????瀹?榛?璁ゅ?鹼?榛?璁や負绌哄??绗?覆??<c:out>??绛劇????绛句?????瀹圭?ㄤ???瀹?杈??虹??榛?璁ゅ?鹼?濡???value灞??х???間?涓?ull锛??充嬌??绛句??ㄥ??涓?涓虹┖锛???绛句?????瀹逛?涓?浼?琚?杈??恒??濡???value灞??т???????涓?涓?java.io.Reader瀵矽薄锛?<c:out> ??绛懼?璋??ㄨ?涓?瀵矽薄??toString?規?锛??跺??杈??鴻?峰???瀛?绗?覆??瀹廣??濡???value灞??ф????涓?涓?java.io.Reader瀵矽薄锛?<c:out> ??绛懼?浠?杩?涓?Reader瀵矽薄涓?璇誨???版????杩?琛?杈??猴?褰???澶ч???版??瑕?琚?杈??烘?訛?灏?杩?浜??版??浠?eader瀵矽薄??褰㈠???渚?缁?<c:out>??绛捐?琛?杈??猴?灏?浼???澶ф??楂?绯葷??ц?姐??褰?????scapeXml灞??х??榛?璁よ?劇疆??rue?訛?<c:out>??绛懼?瀵矽?杈??虹???規??瀛?绗???琛?.2杩?琛?杞????濡???灏?escapeXml灞??ц?劇疆涓?alse锛?<c:out>??绛懼?涓?瀵矽?杈??虹???規??瀛?绗??琛?杞?????????存?ヨ??鴻?浜??規??瀛?绗???

渚?绋?8-3??<c:out> ??绛劇??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-3? c_out1.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<%

session.setAttribute("test_session","testValue_session");

%>

?存?ヨ??轟?涓?瀛?绗?覆锛?

<c:outvalue="test" default="123456" /><br /><hr />

杈???eb??涓?涓?瀛??ㄧ??灞??х???鹼?<br />

<c:outvalue="${test_request}" default="杩?涓?灞??т?瀛???/><br/><hr />

杈???eb??涓???test_session灞??х???鹼?<br />

<c:outvalue="${test_session}" />

?

渚?绋?8-3??杩?琛?缁???濡???.1??绀恒??

??.1

渚?绋?8-4??渚?绋?8-5??涓や釜?ㄤ?婕?绀?lt;c:out>??绛劇??escapeXml灞??х??渚?瀛?绋?搴?锛?渚?绋?8-4娌℃??璁劇疆escapeXml灞??э?渚?绋?8-5灏?escapeXml灞??ц?劇疆涓轟?false??

渚?绋?8-4? c_out2.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:outvalue="${null}" >

<meta http-equiv="refresh"content="0;url=http://www.it315.org" />

</c:out>

?

渚?绋?8-5 c_out3.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<c:outvalue="${null}" escapeXml="false">

<metahttp-equiv="refresh" content="0;url=http://www.it315.org" />

</c:out>

?

渚?绋?8-4??渚?绋?8-5??杩?琛?缁???????濡???.2????.3??绀恒??

??.2

??.3

8.3.2 ?<c:set>??绛?/h3>

<c:set>??绛劇?ㄤ?璁劇疆??绉?Web??涓???灞??э?????璁劇疆Web??涓???java.util.Map绫誨????灞??у?矽薄??JavaBean绫誨????灞??у?矽薄??灞??с??<c:set>??绛炬????绉?璇?娉??煎?锛?

璇?娉?1锛?浣跨??alue灞??ц?劇疆??瀹???涓?????涓?灞??х???鹼?

<c:setvalue="value"

??? var="varName"

??? [scope="{page|request|session|application}"]/>

璇?娉?2锛??ㄦ??绛句?涓?璁劇疆??瀹???涓?????涓?灞??х???鹼?

<c:setvar="varName"

??? [scope="{page|request|session|application}"]>

bodycontent

</c:set>

璇?娉?3锛?浣跨??alue灞??ц?劇疆Web??涓???涓?涓?灞??у?矽薄????涓?灞??э?

<c:setvalue="value"

??? target="target"

??? property="propertyName" />

璇?娉?4锛??ㄦ??绛句?涓?璁劇疆Web??涓???涓?涓?灞??у?矽薄????涓?灞??ф?э?

<c:settarget="target"

??? property="propertyName">

bodycontent

</c:set>

<c:set>??绛劇??灞??ц?存??濡?琛?.4??绀恒??

琛?.4 <c:set>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true Object ?ㄤ???瀹?灞??у??
var false String ?ㄤ???瀹?瑕?璁劇疆??Web??灞??х????绉?
scope false String ?ㄤ???瀹?灞??ф???ㄧ??Web??
target true Object ?ㄤ???瀹?瑕?璁劇疆灞??х??瀵矽薄锛?杩?涓?瀵矽薄蹇?椤繪??JavaBean瀵矽薄??java.util.Map瀵矽薄
property true string ?ㄤ???瀹?褰???瑕?涓哄?矽薄璁劇疆??灞??у??绉?

?

濡???浣跨?ㄧ??1绉?璇?娉??煎??剁??value灞??у?間負null锛?????浣跨?ㄧ??2绉?璇?娉??煎??剁????绛句???瀹逛負绌猴?<c:set>??绛懼?浠?scope灞??ф??瀹????????翠腑????ar灞??ф??瀹???灞??с??

?ㄧ??3绉?璇?娉??煎???绗?4璇?娉??煎?涓?锛?濡???target灞??х???兼??java.util.Map瀵矽薄锛?property灞??ц〃绀鴻??ap瀵矽薄???抽??瀛?锛?濡???Map瀵矽薄娌℃????瀹????抽??瀛?锛?灏辯?Map瀵矽薄澧?????瀹????抽??瀛?锛?濡???target灞??х???兼??JavaBean瀵矽薄锛?property灞??ц〃绀?avaBean瀵矽薄??灞??э?濡???value??绫誨??涓?JavaBean灞??х??绫誨??涓??歸???訛?浼??規??EL??杞??㈣??????ㄨ?琛?杞?????褰?浣跨?ㄧ??3绉?璇?娉??煎???绗?4绉?璇?娉??煎??訛?濡???target灞??х???間負null(??arget灞??ф??瀹???瀵矽薄涓?瀛???锛?????target灞??х???兼??涓?涓?JavaBean瀵矽薄锛?浣?璇?avaBean涓?涓?瀛???roperty灞??ф??瀹???灞??э?<c:set>??绛懼????哄?甯搞??濡???浣跨?ㄧ??3绉?璇?娉??煎???alue灞??х???間負null锛?????浣跨?ㄧ??4绉?璇?娉??煎??舵??绛句?????瀹逛負绌猴?濡???target灞??х???兼??涓?涓?java.util.Map瀵矽薄锛?灏變?Map瀵矽薄涓?????roperty灞??ф??瀹????抽??瀛?瀵瑰???椤癸?濡???target灞??х???兼??涓?涓?JavaBean瀵矽薄锛?灏卞?JavaBean???稿?灞??х???艱?劇疆涓?ull??

渚?绋?8-6??浣跨??lt;c:set>??绛捐?劇疆??涓?Web??涓???灞??х??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-6 c_set1.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<c:set var="userName"scope="session">

zxx

</c:set>

杈???ession 浣??ㄥ??涓???userNamer灞??х????

<c:out value="${userName}"/><br /><hr />

杈???ession 浣??ㄥ??涓???bookname灞??х????

<c:set var="bookname"scope="session" />

<c:out value="${bookname}" />

?

渚?绋?8-6??杩?琛?缁???濡???.4??绀恒??

??.4

渚?绋?8-7??浣跨??lt;c:set>??绛捐?劇疆UserBean瀵矽薄??Map瀵矽薄??灞??х??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-7? c_set2.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<%@page import="java.util.HashMap" %>

<jsp:useBeanid="user" class="org.it315.UserBean" />

<%?

HashMap preferences = new HashMap();

session.setAttribute("preferences",preferences);

%>

璁劇疆??杈???serBean瀵矽薄??userName灞??у??

<c:setvalue="zxx" target="${user}" property="userName"/>

<c:outvalue="${user.userName}" /><br /><hr />

璁劇疆??杈???serBean瀵矽薄??password灞??у??

<c:settarget="${user}" property="password" />

<c:outvalue="${user.password}" /><br /><hr />

璁劇疆??杈???ap瀵矽薄??color?抽??瀛?????

<c:settarget="${preferences}" property="color"value="${param.color}" />

<c:outvalue="${preferences.color}" />

?

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??渚?绋?8-7锛?

http://localhost:8080/JSTL/c_set2.jsp?color=green

渚?绋?8-7??杩?琛?缁???濡???.5??绀恒??

??.5

8.3.3 ?<c:remove>??绛?/h3>

<c:remove>??绛劇?ㄤ????ゅ??绉?Web??涓???灞??э??惰??娉??煎?濡?涓?锛?

<c:removevar="varName" ??

??? [scope="{page|request|session|application}"]/>

var灞??х?ㄤ???瀹?瑕????ょ??灞??х????绉幫?scope灞??х?ㄤ???瀹?瑕????ょ??灞??ф??灞???Web??锛?瀹?浠????奸?戒??芥?ュ???ㄦ???箋??濡???娌℃????瀹?scope灞??э?<c:remove>??绛懼氨璋???ageContext.removeAttribute(varName)?規?锛?????灏辮???ageContext.removeAttribute(varName, scope) ?規???<c:remove>涓?<c:set>??绛劇??涓?绉?璇?娉??煎???value灞??у?間負null?剁??浣??ㄧ?稿????

渚?绋?8-8??浣跨??lt;c:remove>??绛劇??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-8 c_remove.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<c:setvalue="org.it315" var="company" scope="request"/>

<c:setvar="passWord" scope="session">

a123456a

</c:set>

?ㄦ病??浣跨??&lt;c:remove&gt; ??绛句???锛????????間負锛?<br />

company:<c:outvalue="${company}" /><br />

passWord:<c:outvalue="${passWord}" /><br />

<c:remove var="company" scope="request" />

<!--c:setvar="company" scope="request" 姝よ?涓?榛?浣?瀛???涓?琛?浣??ㄦ??涓??風??/-->

<c:removevar="passWord" scope="session" /><hr />

?ㄤ嬌??&lt;c:remove&gt; ??绛句???锛????????間負锛?<br />

company:<c:outvalue="${company}" /><br />

passWord:<c:outvalue="${passWord}" />

?

渚?绋?8-8??杩?琛?缁???濡???.6??绀恒??

??.6

8.3.4 ?<c:catch>??绛?/h3>

<c:catch>??绛劇?ㄤ????峰?濂??ㄦ??绛句?涓?????瀹規???虹??寮?甯革??惰??娉??煎?濡?涓?锛?

<c:catch[var="varName"]>

nestedactions

</c:catch>

var灞??х?ㄤ???璇?<c:catch>??绛炬???風??寮?甯稿?矽薄锛??跺?兼??涓?涓???????瀛?绗?覆锛?涓??????ㄦ??灞??у?箋??<c:catch>??绛懼????風??寮?甯稿?矽薄浠?ar??瀹?????绉頒?瀛???age杩?涓?Web??涓?锛?濡???娌℃????瀹?var灞??э???<c:catch>??绛句????峰?甯革?涓???age??淇?瀛?寮?甯稿?矽薄??濡???<c:catch>??绛句?涓?????瀹規病?????哄?甯革?<c:catch>??绛懼?浠?page??涓?????ar灞??ф??瀹???灞??с??

<c:catch>??绛懼??浠ユ???蜂換浣???绛炬???虹??寮?甯革?骞朵???浠ュ???跺???澶?涓???绛炬???虹??寮?甯革?杩??鳳???浠ュ??SP椤甸?㈢??寮?甯歌?琛?缁?涓?澶???锛??劇ず缁??ㄦ?蜂?涓??村??濂界??椤甸????JSP澶???寮?甯哥?????ㄦ?哄?舵???虹?伴??瑕?寮?甯稿??璺寵漿?伴??璇?澶???椤甸???寤鴻??灏介??涓?瑕???lt;c:catch>??绛炬?ヤ唬??SP????璇?澶????哄?訛???瀵逛?浜?娆¤?寮?甯告??浣跨??lt;c:catch>??绛捐?琛????峰?????

渚?绋?8-9??浣跨??lt;c:catch>??绛捐?琛?寮?甯告???峰?????涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-9 ?c_catch.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<c:catch var="myex">

<%

int i = 0;

int j = 10;

out.println(j +"/" + i + "=" + j/i);

%>

</c:catch>

寮?甯革?<c:out value="${myex}" /><br />

寮?甯?myex.getMessage锛?<c:outvalue="${myex.message}" /><br />

寮?甯?myex.getCause锛?<c:outvalue="${myex.cause}" /><br />

寮?甯?myex.getStackTrace锛?<c:outvalue="${myex.stackTrace}" />

?

?ㄤ?绋?8-9涓?锛?<c:catch>??绛懼??宓?濂?????????绱????轟?寮?甯革?<c:catch var="myex">灏????峰?拌?涓?寮?甯革?璋???lt;c:out value="${myex.message}" />锛??稿?浜?璋???lt;%=myex.getMessage()%>??渚?绋?8-9??杩?琛?缁???濡???.7??绀恒??

??.7

8.3.5? <c:if>??绛?/h3>

JSP椤甸?㈢???劇ず?昏?涓?涔?缁?甯擱??瑕?杩?琛??′歡?ゆ??锛?<c:if>??绛懼??浠ユ????绠???????if-then??缁??????′歡琛ㄨ揪寮?锛?濡????′歡琛ㄨ揪寮???缁???涓虹??灏辨?ц???绛句??ㄥ??????瀹廣??<c:if>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<c:if test="testCondition" var="varName"

??????? [scope="{page|request|session|application}"] />

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹?瑕??ц?????瀹癸?

<c:if test="testCondition" [var="varName"]

??????? [scope="{page|request|session|application}"]>

??? bodycontent

</c:if>

<c:if>??绛劇??灞??ц?存??濡?琛?.5??绀恒??

琛?.5 ??<c:if>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
test true boolean ?沖???????????绛句?涓?????瀹圭???′歡琛ㄨ揪寮?
var false String ?ㄤ???瀹?灏?test灞??х???ц?缁???淇?瀛??版??涓?Web??涓?????涓?灞??х????绉?
scope false String ??瀹?灏?test灞??х???ц?缁???淇?瀛??闆??涓?Web??涓?

?

瀵逛?璇?娉?2锛?濡?????瀹?浜?<c:if>??绛劇??scope灞??э???蹇?椤繪??瀹?var灞??с??

渚?绋?8-10??浣跨??lt;c:if>??绛劇??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-10 ?c_if.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<jsp:useBeanid="user" class="org.it315.UserBean" />

<c:setvalue="${param.count}" target="${user}"property="visitCount" />

<c:iftest="${user.visitCount == 1}">

杩????ㄧ??涓?娆¤?塊????缃?绔?锛?娆㈣????

</c:if>

?

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??渚?绋?8-10锛?

http://localhost:8080/JSTL/c_if.jsp?count=1

渚?绋?8-10??杩?琛?缁???濡???.8??绀恒??

??.8

8.3.6? <c:choose>??绛?/h3>

<c:choose>??绛劇?ㄤ???瀹?澶?涓??′歡???╃??缁???杈圭??锛?瀹?蹇?椤諱?<c:when>??<c:otherwise>??绛句?璧蜂嬌?ㄣ??浣跨??lt;c:choose>锛?<c:when>??<c:otherwise>涓?涓???绛撅???浠ユ????绫諱技 ??if-else if-else?? ??澶????′歡?ゆ??缁?????

<c:choose>??绛炬病??灞??э??ㄥ??????绛句??????藉?濂?涓?涓???澶?涓?<c:when>??绛懼??0涓???涓?涓?<c:otherwise>??绛撅?骞朵???涓?涓?<c:choose>??绛句腑??????<c:when>瀛???绛懼?椤誨?虹?闆??lt;c:otherwise>瀛???绛句?????濡???<c:choose>??绛懼??宓?濂?涓?涓?<c:when>??绛懼??<c:otherwise>??绛撅?灏辯?稿?浜???if-else?????′歡?ゆ??缁???锛?濡???<c:choose>??绛懼??宓?濂?澶?涓?<c:when>??绛懼??涓?涓?<c:otherwise>??绛撅?灏辯?稿?浜???if-else if-else????绛俱??

<c:when>??绛懼????涓?涓?test灞??э?璇ュ??х???間負甯?灏?绫誨????test灞??ф?????ㄦ???鹼??跺?煎??浠ユ??涓?涓??′歡琛ㄨ揪寮?锛?濡????′歡琛ㄨ揪寮????間負true锛?灏辨?ц?杩?涓?<c:when>??绛句?????瀹廣??<c:when>??绛句?????瀹瑰??浠ユ??浠繪????JSP浠g????<c:otherwise>??绛炬病??灞??э?瀹?蹇?椤諱?涓?lt;c:choose>??绛劇???????????虹?般??

褰?JSP椤甸??腑浣跨??lt;c:choose>??绛炬?訛?宓?濂???lt;c:choose>??绛懼????test?′歡??绔???绗?涓?涓?<c:when>??绛劇????绛句???瀹瑰?琚??ц???杈??恒??褰?涓?浠?褰???????<c:when>??绛劇??test?′歡?戒???绔??訛????ц???杈???lt;c:otherwise>??绛劇????绛句???瀹廣??濡?????????<c:when>??绛劇??test?′歡?戒???绔?锛?骞朵?<c:choose>??绛懼??娌℃??宓?濂?<c:otherwise>??绛撅???涓??ц?浠諱???浣???

渚?绋?8-11??浣跨??lt;c:choose>??<c:when>??<c:otherwise>??绛劇??涓?涓?婕?绀轟?瀛?绋?搴???

渚?绋?8-11 c_choose.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<c:setvalue="${param.count}" var="count" />

<c:choose>

<c:when test="${count == 0}">

??? 瀵逛?璧鳳?娌℃??绗????ㄨ?姹???璁闆???

</c:when>

<c:otherwise>

??? 绗????ㄨ?姹???璁闆??辨??${count}??

</c:otherwise>

</c:choose>

?

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??渚?绋?8-11锛?

http://localhost:8080/JSTL/c_choose.jsp?count=0

渚?绋?8-11??杩?琛?缁???濡???.9??绀恒??濡???灏?????ount???間慨?逛負10锛???杩?琛?缁???濡???.10??绀恒??

?

?

??.9

??.10

?

渚?绋?8-12??涓?涓?缁煎??浣跨??lt;c:if>??绛懼??<c:choose>绛???绛劇??渚?瀛?绋?搴?锛??ㄨ?涓?渚?瀛?绋?搴?涓?锛?棣???浣跨??lt;c:if>??绛懼?ゆ??琛ㄥ????浜ょ???瑰???????POST锛?濡?????锛?灏卞??浣跨??lt;c:choose>绛???绛炬?規??琛ㄥ????浜ょ????瀹矽?琛?涓?????澶?????

渚?绋?8-12? c_customLogic.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<c:iftest="${pageContext.request.method=='POST'}">

?????? <c:choose>

????????????? <c:whentest="${param.favor == 'computer'}">

???????????????????? Yourfavourite course is <b>computer</b>.

????????????? </c:when>

????????????? <c:otherwise>

???????????????????? Yourfavourite course is <i>other</i>.

????????????? </c:otherwise>

?????? </c:choose>

</c:if>

<formmethod="POST">What is your favourite course?<br/>

<input type="text"name="favor" />

<input type="submit"value="submit" />

</form>

?

?ㄦ?瑙??ㄥ?闆????涓??存?ヨ?塊??c_customLogic.jsp??杩?琛?缁???濡???.11??绀猴??ㄦ????妗?涓?杈??モ??computer??锛????誨?朵腑??submit????????杩?琛?缁???濡???.12??绀恒??

??.11

??.12

8.3.7? <c:forEach>??绛?/h3>

JSP椤甸?㈢???劇ず?昏?涓?涔?缁?甯擱??瑕?瀵歸????瀵矽薄杩?琛?寰???杩?浠f??浣?锛?<c:forEach>??绛劇?ㄤ?瀵逛?涓?????瀵矽薄涓?????绱?杩?琛?寰???杩?浠f??浣?锛?????????瀹???娆℃?伴??澶?杩?浠f?ц???绛句?涓?????瀹廣??<c:forEach>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛??ㄩ????瀵矽薄涓?杩?浠o?

<c:forEach [var="varName"]

??? ??? ??? items="collection"

??? ??? ??? [varStatus="varStatusName"]

??? ??? ??? [begin="begin"] [end="end"] [step="step"]>

??? body content

</c:forEach>

璇?娉?2锛?杩?浠e?哄????娆℃?幫?

<c:forEach [var="varName"]

??????????? [varStatus="varStatusName"]

??????????? begin="begin" end="end" [step="step"]>

??? body content

</c:forEach>

<c:forEach>??绛劇??灞??ц?存??濡?琛?.6??绀恒??

琛?.6? <c:forEach>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
var false String ??瀹?灏?褰???杩?浠e?扮????绱?淇?瀛???age杩?涓?Web??涓???灞??у??绉?
items true 浠諱???????绫誨?? 灏?瑕?杩?浠g??????瀵矽薄
varStatus false String ??瀹?灏?浠h〃褰???杩?浠g?舵??淇℃????瀵矽薄淇?瀛???age杩?涓?Web??涓???灞??у??绉?
begin true int 濡?????瀹?items灞??э?灏變?????涓???绗?begin涓???绱?寮?濮?杩?琛?杩?浠o?begin??绱㈠??間?0寮?濮?缂??鳳?濡???娌℃????瀹?items灞??э?灏變?begin??瀹????煎?濮?杩?浠o??村??nd?兼?剁???杩?浠?
end true int ????begin灞??х????杩?
step true int ??瀹?杩?浠g??姝ラ?匡??寵凱浠e??瀛???杩?浠e???

?

?ㄤ嬌??lt;c:forEach>??绛炬?訛???瑕?娉ㄦ??濡?涓????矽?存??锛?

l? 濡?????瀹?begin灞??э??跺?煎?椤誨ぇ浜???绛?浜??訛?

l? 濡?????瀹?姝ラ?匡?step灞??э?锛??跺?煎?椤誨ぇ浜???绛?浜?1锛?

l? 濡???items灞??х???間負null锛???瑕?澶?????????瀵矽薄涓虹┖锛?杩??朵??ц?杩?浠f??浣?锛?

l? 濡?????瀹???begin灞??х???煎ぇ浜???绛?浜?????瀵矽薄???垮害锛?涓??ц?杩?浠f??浣?锛?

l? 濡?????瀹???end灞??х???煎?浜?begin灞??х???鹼?涓??ц?杩?浠f??浣?锛?

?

<c:forEach>??绛劇??items灞??х???兼????涓??㈢???版??绫誨??锛?

l? 浠繪??绫誨?????扮?

l? java.util.Collection

l? java.util.Iterator

l? java.util.Enumeration

l? java.util.Map

l? String

items灞??ц?????涓??版??搴????崇???版??绫誨??java.sql.ResultSet(????javax.sql.RowSet)锛?杩?浜??版??绫誨??灏???.5 ?????版??搴???绛句腑杩?琛?浠?缁???瀵瑰??绗?覆??杩?浠f??浣???甯鎬嬌??lt;c:forTokens>??绛炬??JSTL?芥?幫?渚?濡?fn:split??fn:jion锛?JSTL?芥?闆???.7??杩?琛?浠?缁???

?

1锛?杩?浠?ollection绫誨????????瀵矽薄

渚?绋?8-13??浣跨??lt;c:forEach>??绛捐凱浠?ollection绫誨????????瀵矽薄??涓?涓?搴??ㄤ婦渚???

渚?绋?8-13? c_forEach_collection.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<%@page import="java.util.*,org.it315.UserBean" %>

<%

?????? Collection users = new ArrayList();

?????? for(int i=0; i<5; i++)

?????? {

????????????? UserBean user = new UserBean();

????????????? user.setUserName("user"+ i);

????????????? user.setPassword("guess"+ i);

????????????? users.add(user);

?????? }

?????? session.setAttribute("users",users);

%>

?????? <divstyle="text-align:center">User List

?????? <table >

????????????? <tr><td>?ㄦ?峰??</td><td>瀵???</td></tr>

????????????? <c:forEach var="user"items="${users}">

???????????????????? <tr>

??????????????????????????? <td>${user.userName}</td><td>${user.password}</td>

???????????????????? </tr>

????????????? </c:forEach>

?????? </table></div>

?

渚?绋?8-13??杩?琛?缁???濡???.13??绀恒??

??.13

2锛?杩?浠?ap瀵矽薄

浣跨??lt;c:forEach>??绛捐凱浠?ap绫誨????????瀵矽薄?訛?杩?浠e?虹??姣?涓???绱???绫誨??涓?ap.Entry锛?Map.Entry浠h〃Map????涓???涓?涓??$??椤癸??朵腑??getKey()?規????峰??$??椤圭???抽??瀛?锛?getValue()?規????峰??$??椤圭???箋??

EL涓???requestScope????瀵矽薄浠h〃request浣??ㄥ??涓???????灞??х??Map瀵矽薄锛???浠ユ??浠???浠ヤ嬌??lt;c:forEach>??绛捐凱浠h???L涓???requestScope????瀵矽薄涓?????????绱?锛?濡?渚?绋?8-14??绀恒??

渚?绋?8-14 c_forEach_map.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

?????? <%

????????????? request.setAttribute("attr1","value1");

????????????? request.setAttribute("attr2","value2");

?????? %>

?????? <divstyle="text-align:center">Properties(Map)

?????? <table >

????????????? <tr><td>Map???抽??瀛?</td><td>Map??瀵瑰??抽??瀛?????lt;/td></tr>

????????????? <c:forEachvar="entry" items="${requestScope}">

???????????????????? <tr><td>${entry.key}</td><td>${entry.value}</td></tr>

????????????? </c:forEach>

?????? </table></div>

?

渚?绋?8-14??杩?琛?缁???濡???.14??绀恒??

??.14

3锛?杩?浠f??瀹???娆℃??

<c:forEach>??绛懼??浠ユ????瀹???娆℃?伴??澶?杩?浠f?ц???绛句?涓?????瀹癸?浣跨?ㄨ?绉??瑰?杩?浠f?訛???浠ユ??瀹?杩?浠g??姝ラ?褲??渚?绋?8-15涓?????婕?绀轟???瀹?杩?浠f?ラ?垮??娌℃????瀹?杩?浠f?ラ?跨?????點??

渚?绋?8-15 c_forEach_count.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

浠?11??6杩?浠o???瀹?杩?浠f?ラ?誇負2锛?

<c:forEachvar="i" begin="11" end="16"step="2">

?????? ${i}

</c:forEach><br/><hr />

浠?0??杩?浠o?娌℃????瀹?杩?浠f?ラ?匡?

<c:forEachvar="i" begin="0" end="5">

?????? ${i}

</c:forEach>

?

渚?绋?8-15??杩?琛?缁???濡???.15??绀恒??

??.15

4锛???瀹?杩?浠i????瀵矽薄?????村??姝ラ??

<c:forEach>??绛捐凱浠i????绫誨?矽薄?訛?涔???浠ユ??瀹?杩?浠g?????村??姝ラ?匡?濡?渚?绋?8-16??绀恒??

渚?绋?8-16 c_forEach_col.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<%@ page import="java.util.*,org.it315.UserBean"%>

<%

??? Collection users =new ArrayList();

??? for(int i=0;i<6; i++)

??? {

??????? UserBean user= new UserBean();

??????? user.setUserName("user"+ i);

??????? user.setPassword("guest"+ i);

??????? users.add(user);

??? }

??? session.setAttribute("users",users);

%>

<div style="text-align:center">User List(??瀹?杩?浠h???村??姝ラ??

<table >

??? <tr><td>?ㄦ?峰??</td><td>瀵???</td></tr>

??? <c:forEachvar="user" items="${users}" end="5"step="2">

??????? <tr>

??????????? <td>${user.userName}</td><td>${user.password}</td>

??????? </tr>

??? </c:forEach>

</table></div>

?

渚?绋?8-16??杩?琛?缁???濡???.16??绀恒??

??.16

5锛??峰??杩?浠g???舵??淇℃??

涓?绠℃??杩?浠i????瀵矽薄锛?杩???杩?浠f??瀹???娆℃?幫??ㄨ凱浠f?堕?藉??浠ヨ?峰?褰?????杩?浠g?舵??淇℃????<c:forEach>??绛懼??浠ュ?浠h〃褰???杩?浠g?舵??淇℃????瀵矽薄淇?瀛???age??涓?锛?varStatus灞??ф??瀹?浜?杩?涓?瀵矽薄淇?瀛???age??涓???灞??у??绉般??浠h〃褰???杩?浠g?舵??淇℃????瀵矽薄??绫誨??涓?avax.servlet.jsp.jstl.core.LoopTagStatus锛?浠?JSTL瑙???涓???浠ユ?ョ???拌?涓?绫葷??璇??淇℃??锛??朵腑瀹?涔?浜?濡?涓?涓?浜??規?锛?

l? publicjava.lang.Integer getBegin()

杩???涓烘??绛捐?劇疆??begin灞??х???鹼?濡???娌℃??璁劇疆begin灞??у??杩???null

l? publicint getCount()

杩???褰???宸插驚??杩?浠g??娆℃??

l? publicjava.lang.Object getCurrent()

杩???褰???杩?浠e?扮????绱?瀵矽薄

l? publicjava.lang.Integer getEnd()

杩???涓烘??绛捐?劇疆??end灞??х???鹼?濡???娌℃??璁劇疆end灞??у??杩???null

l? public int getIndex()

杩???褰???杩?浠g??绱㈠???

l? publicjava.lang.Integer getStep()

杩???涓烘??绛捐?劇疆??step灞??х???鹼?濡???娌℃??璁劇疆step灞??у??杩???null

l? publicboolean isFirst()

杩???褰?????????绗?涓?娆¤凱浠f??浣?

l? publicboolean isLast()

杩???褰?????????????涓?娆¤凱浠f??浣?

?

渚?绋?8-17??涓?涓??峰??杩?浠g?舵??淇℃????渚?瀛?绋?搴???

渚?绋?8-17 c_forEach_col2.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<%@ pageimport="java.util.*,org.it315.UserBean" %>

<%

??? Collection users =new ArrayList();

??? for(int i=0;i<6; i++)

??? {

??????? UserBean user= new UserBean();

??????? user.setUserName("user"+ i);

??????? user.setPassword("guest"+ i);

??????? users.add(user);

??? }

??? session.setAttribute("users",users);

%>

<div style="text-align:center">User List

<table >

??? <tr><td>?ㄦ?峰??</td><td>瀵???</td><td>index</td>

??? <td>count</td><td>first?</td><td>last?</td></tr>

??? <c:forEachvar="user" items="${users}" varStatus="sta"begin="1" step="2">

??????? <tr>

??????????? <td>${user.userName}</td><td>${user.password}</td>

??????????? <td>${sta.index}</td><td>${sta.count}</td>

??????????? <td>${sta.first}</td><td>${sta.last}</td>

??????? </tr>

??? </c:forEach>

</table></div><hr>

?

<div style="text-align:center">杩?浠e?哄????娆℃??

<table >

??? <tr><td>?闆??lt;/td><td>index</td><td>count</td>

??? <td>first?</td><td>last?</td></tr>

??? <c:forEachvar="i" varStatus="sta1" begin="101"end="103">

??????? <tr>

??????????? <td>${i}</td><td>${sta1.index}</td><td>${sta1.count}</td>

??????????? <td>${sta1.first}</td><td>${sta1.last}</td>

??????? </tr>

??? </c:forEach>

</table></div>

?

渚?绋?8-17??杩?琛?缁???濡???-17??绀恒??

??.17

6锛?涓??′歡??绛劇???浣跨??

杩?浠f??绛懼??浠ヤ??′歡??绛劇???浣跨???瀵規?版??杩?琛????′歡??杩?浠o?搴??ㄤ婦渚?濡?渚?绋?8-18??绀恒??

渚?绋?8-18 c_forEach_com.jsp

?

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

<%@page contentType="text/html;charset=gb2312" %>

<divstyle="text-align:center">

<table><tr><td>number</td><td>count</td><td>even|odd</td></tr>

<c:forEachvar="i" begin="11" end="13"varStatus="status">

?????? <tr><td>${i}</td><td>${status.count}</td><td>

?????? <c:choose>

????????????? <c:whentest="${status.count % 2 == 0}">

???????????????????? ?舵?拌?

????????????? </c:when>

????????????? <c:otherwise>

???????????????????? 濂??拌?

????????????? </c:otherwise>

?????? </c:choose></td></tr>

</c:forEach>

<table></div>

?

渚?绋?8-18??杩?琛?缁???濡???.18??绀恒??

??.18

8.3.8? <c:forTokens>??绛?/h3>

<c:forTokens>??绛句??ㄧ?ㄤ?瀹??扮被浼?ava.util.StringTokenizer绫葷??杩?浠e???斤?浣?瀹???浠ュ??涓?瀛?绗??涓哄????绗?????跺??浠ユ??瀹?澶?涓?瀛?绗??涓哄?涓?骞惰???????绗???<c:forTokens>??绛劇??璇?娉??煎?濡?涓?锛?

<c:forTokensitems="stringOfTokens"delims="delimiters"

????? [var="varName"]

????? [varStatus="varStatusName"]

????? [begin="begin"] [end="end"][step="step"]>

bodycontent

</c:forTokens>

<c:forTokens>??绛劇??灞??ц?存??濡?琛?.7??绀恒??

琛?.7? c:forTokens

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
var false String ??瀹?灏?褰???杩?浠e?虹??瀛?瀛?绗?覆淇?瀛???age杩?涓?Web??涓???灞??у??绉?
items true String 灏?瑕?杩?浠g??瀛?绗?覆
delims true String ??瀹?涓?涓???澶?涓?????绗?
varStatus false String ??瀹?灏?浠h〃褰???杩?浠g?舵??淇℃????瀵矽薄淇?瀛???age杩?涓?Web??涓???灞??у??绉幫?浠h〃褰???杩?浠g???舵??淇℃????瀵矽薄??绫誨??涓?avax.servlet.jsp.jstl.core.LoopTagStatus锛?浠?JSTL瑙???涓???浠ユ?ョ??杩?涓?绫葷??璇??淇℃??
begin true int ??瀹?浠?绗?begin涓?瀛?瀛?绗?覆寮?濮?杩?琛?杩?浠o?begin??绱㈠??間?0寮?濮?缂???
end true int ??瀹?杩?浠e?扮??begin涓?瀛?瀛?绗?覆锛?begin??绱㈠??間?0寮?濮?缂???
step true int ??瀹?杩?浠g??姝ラ?匡??蟲??娆¤凱浠e????杩?浠e??瀛?澧???

?

?ㄤ嬌??lt;c:forTokens>??绛炬?訛???瑕?娉ㄦ??濡?涓????矽?存??锛?

l? 濡?????瀹?begin灞??э??跺?煎?椤誨ぇ浜???绛?浜??躲??

l? 濡?????瀹?姝ラ?匡?step灞??э?锛??跺?煎?椤誨ぇ浜???绛?浜?1??

l? 濡?????瀹???end灞??х???煎?浜?begin灞??х???鹼?涓??ц?杩?浠f??浣???

渚?绋?8-19??涓?涓?浣跨??lt;c:forTokens>??绛劇??渚?瀛?绋?搴???

渚?绋?8-19 c_forTokens.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

浣跨??|"浣?涓哄????绗?lt;br/>

<c:forTokens var="token"items="spring,summer|autumn,winter" delims="|">

${token}&copy;

</c:forTokens><br />

浣跨??|"??","浣?涓哄????绗?lt;br />

<c:forTokens var="token"items="spring,summer|autumn,winter" delims="|," end="3">

${token}&copy;

</c:forTokens><br />

浣跨??-"浣?涓哄????绗?lt;br/>

<c:forTokens var="token"items="year--season--month-week" delims="-">

${token}&copy;

</c:forTokens>

?

渚?绋?8-19??杩?琛?缁???濡???.19 ??绀恒??

??.19

8.3.9? URL?稿?崇????绛炬?杩?/h3>

JSTL?稿???绛懼?涓???渚?浜?濡?涓?涓?浜?涓?URL??浣??稿?崇????绛撅?

l? <c:import>

l?<c:url>

l?<c:redirect>

l? <c:param>

?ㄤ婦渚?璁茶В涓??㈢????浜???绛炬?訛?瑕?寮??ㄥ???涓?涓?JSP??浠訛?杩???????寤哄ソ杩?涓?JSP??浠訛?濡?渚?绋?8-20??绀恒??

渚?绋?8-20 register.jsp

?

<%@ taglibprefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%@ pagecontentType="text/html;charset=gb2312" %>

<%

??? String name = request.getParameter("name");

??? name = newString(name.getBytes("iso-8859-1"),"gb2312");

??? session.setAttribute("name",name);

??? String country = request.getParameter("country");

??? country = newString(country.getBytes("iso-8859-1"),"gb2312");

??? session.setAttribute("country",country);

%>

name=${name};

country=${country}<br />

?

8.3.10? <c:param>??绛?/h3>

??SP椤甸?㈣?琛?URL???稿?蟲??浣??訛?缁?甯歌???RL?闆?????㈤????涓?浜????般??<c:param>??绛懼??浠ュ?濂???lt;c:import>??<c:url>??<c:redirect>??绛懼??锛?涓鴻?浜???绛炬??浣跨?ㄧ??URL?闆?????????般??<c:param>??绛懼?ㄤ負涓?涓?URL?闆?????????版?訛?灏????ㄥ?瑰???闆?艱?琛?URL缂???锛?渚?濡?锛?濡???浼????????闆?間負??涓??解??锛???灏??惰漿??負??%d6%d0%b9%fa????????????RL?闆???????杩?涔?灏辨??浣跨??lt;c:param>??绛劇????澶уソ澶???<c:param>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?浣跨??alue灞??ф??瀹????扮???鹼?

<c:param name="name" value="value" />

璇?娉?2锛??ㄦ??绛句?涓???瀹????扮???鹼?

<c:param name="name">

??? parameter value

</c:param>

<c:param>??绛劇??灞??ц?存??濡?琛?.8??绀恒??

琛?.8? <c:param>??绛劇??灞???

8.3.11? <c:url>??绛?/h3>

<c:url>??绛劇?ㄤ???SP椤甸??腑????涓?涓?URL?闆??锛??朵富瑕???????瀹???RL??????URL????灏辨??灏?浼?璇???璇??蜂互???闆艦寮???????RL?闆???????璇??缁???璇峰????绗???缂???????娣卞?ヤ?楠?java Web寮?????骞??????稿??虹???涓?涔?腑??绗?7.4.8??璁茶В??<c:url>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<c:url value="value"

??????? [context="context"]

??????? [var="varName"]

??????? [scope="{page|request|session|application}"] />

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹???????URL?????幫?

<c:url value="value"

??????? [context="context"]

??????? [var="varName"]

??????? [scope="{page|request|session|application}"]>

??? <c:param>??绛?

</c:url>

<c:url>??绛劇??灞??ц?存??濡?琛?.9??绀恒??

琛?.9? <c:url>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true String ??瀹?瑕???????URL
context true String 褰?瑕?浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ??涓?涓????″?ㄤ????朵?WEB搴??ㄧ?搴?涓???URL?闆???訛?context灞??ф??瀹??朵?WEB搴??ㄧ?搴?????绉?
var false String ??瀹?灏??????虹??URL缁???淇?瀛???eb??涓???灞??у??绉?
scope false String ??瀹?灏??????虹??URL缁???淇?瀛??闆??涓?Web??涓?

?

value灞??ф????瀹???URL??浠ユ???稿?矽礬寰???缁?瀵矽礬寰?锛??跺?蜂?缁???涓?8.3.12????<c:import>??绛劇??url灞??х??缁????稿????浣跨??lt;c:url>??绛炬????URL?訛???浠ラ??杩?宓?濂???<c:param>??绛炬??瀹????幫?????alue灞??т腑?存?ユ??瀹????般??

渚?绋?8-21??涓?涓?浣跨??lt;c:url>??绛劇??渚?瀛?绋?搴???

渚?绋?8-21 c_url.jsp

?

<%@ taglibprefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

浣跨?ㄧ?瀵矽礬寰?????URL:

<c:urlvalue="http://localhost:8080/JSTL/URL/register.jsp"var="myUrl1">

?????? <c:param name="name"value="寮?涓?"/>

?????? <c:param name="country"value="${param.country}" />

</c:url>

<ahref="${myUrl1}" target="_blank" rel="external nofollow" >Register1</a><hr />

浣跨?ㄧ?稿?瑰???JSP椤甸?㈢??璺?寰?????URL:

<c:urlvalue="register.jsp?name=wangwu&country=France" var="myUrl2"/>

<ahref="${myUrl2}" target="_blank" rel="external nofollow" >Register2</a><hr />

浣跨?ㄧ?稿?瑰???WEB搴??ㄧ??璺?寰?????URL:

<c:urlvalue="/URL/register.jsp?name=zhaoliu&country=England"var="myUrl3" />

<ahref="${myUrl3}" target="_blank" rel="external nofollow" >Register3</a>

?

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??渚?绋?8-21锛?

http://localhost:8080/JSTL/c_url.jsp?country=China

?ョ??渚?绋?8-21??杩?琛?缁?????婧???浠訛???瀹瑰?渚?绋?8-22??绀恒??

渚?绋?8-22 c_url.jsp杩?琛?缁?????婧???浠?

?

浣跨?ㄧ?瀵矽礬寰?????URL:

<ahref="http://localhost:8080/JSTL/URL/register.jsp?name=%d5%c5%c8%fd&country=China" target="_blank" rel="external nofollow" >Register1</a><hr/>

浣跨?ㄧ?稿?瑰???JSP椤甸?㈢??璺?寰?????URL:

<ahref="register.jsp?name=wangwu&country=France" target="_blank" rel="external nofollow" >Register2</a><hr/>

浣跨?ㄧ?稿?瑰???WEB搴??ㄧ??璺?寰?????URL:

<ahref="/JSTL/URL/register.jsp?name=zhaoliu&country=England" target="_blank" rel="external nofollow" >Register3</a>

?

8.3.12? <c:import>??绛?/h3>

<c:import>??绛劇?ㄤ???SP椤甸??腑瀵煎?ヤ?涓?URL?闆????????璧?婧???瀹癸??朵??ㄦ???圭被浼?lt;jsp:include>杩?涓?JSP??????绛撅?浣????芥?村己澶с??<c:import>??绛炬??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?灏?URL?闆????????璧?婧???瀹逛互瀛?绗?覆褰㈠?杈??烘??浠ュ??绗?覆褰㈠?淇?瀛??頒?涓?????涓?锛?

<c:importurl="url"

????????????? [context="context"]

????????????? [var="varName"]

????????????? [scope="{page|request|session|application}"]

????????????? [charEncoding="charEncoding"]>

?????? optionalbody content for <c:param> subtags

</c:import>

璇?娉?2锛?灏?URL?闆????????璧?婧???瀹逛?瀛??頒?涓?Reader瀵矽薄涓?锛?

<c:importurl="url"

????????????? [context="context"]

????????????? varReader="varReaderName"

????????????? [charEncoding="charEncoding"]>

?????? bodycontent where varReader is consumed by another action

</c:import>

<c:import>??绛劇??灞??ц?存??濡?琛?.10??绀恒??

琛?.10? <c:import>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
url true String ??瀹?瑕?瀵煎?ョ??璧?婧???URL?闆??
context true String 褰?瑕?浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ??涓?涓????″?ㄤ????朵?WEB搴??ㄧ?搴?涓???璧?婧??訛?context灞??ф??瀹??朵?WEB搴??ㄧ?搴?????绉?
var false String ??瀹?灏?瀵煎?ョ??璧?婧???瀹逛?瀛???eb??涓???灞??у??绉?
scope false String ??瀹?灏?瀵煎?ョ??璧?婧???瀹逛?瀛??闆??涓?Web??涓?
charEncoding true String 灏?瀵煎?ョ??璧?婧???瀹矽漿?㈡??瀛?绗?覆?舵??浣跨?ㄧ??瀛?绗???缂???
varReader false String ??瀹?灏?瀵煎?ョ??璧?婧???瀹逛?瀛???age??涓???涓?涓?java.io.Reader瀵矽薄涓?锛?varReader灞??ф??瀹?浜?璇?eader瀵矽薄??age杩?涓?Web??涓???灞??у??绉般??

?

浣跨??lt;c:import>??绛懼?煎?ュ?朵?璧?婧???浠舵?訛?濡???琚?瀵煎?ョ??璧?婧???浠朵腑??????ASCII??瀛?绗??蹇?椤繪敞????瀹?charEncoding灞??э???????浠ヤ?璁劇疆杩?涓?灞??с??

褰?浣跨?ㄧ??1绉?璇?娉??煎??訛?濡?????瀹?浜?var灞??э?瀵煎?ョ??璧?婧???瀹逛互瀛?绗?覆褰㈠?淇?瀛??頒?涓?????涓?锛?var灞??ф??瀹?浜?杩?涓?????淇?瀛???cope灞??ф??瀹???Web??涓?????绉幫?濡???娌℃????瀹?var灞??э?瀵煎?ョ??璧?婧???瀹瑰?浠ュ??绗?覆褰㈠??存?ヨ??恒??绗?1绉?璇?娉??煎?????绛句???涓???浠ュ?濂?<c:param>??绛炬?ョ?瀵煎?ョ??璧?婧?浼??????般??

浣跨?ㄧ??2绉?璇?娉??煎??訛?瀵煎?ョ??璧?婧???瀹逛?瀛???age??涓???涓?涓?java.io.Reader瀵矽薄涓?锛?varReader灞??ф??瀹?浜?璇?eader瀵矽薄??age杩?涓?Web??涓???灞??у??绉般????涓?lt;c:import>??绛懼?ㄦ??绛劇????跺??抽??Reader瀵矽薄瀵瑰???杈??ユ?锛???浠?arReader灞??ф??瀹??????????ㄦ??绛懼????????绗?2绉?璇?娉??煎?????绛句???涓?搴?璇ヤ????藉?濂?璋???arReader灞??ф??瀹???reader瀵矽薄???朵???绛俱??褰?浣跨?ㄧ??2绉?璇?娉??煎??訛?<c:import>??绛句???涓??藉?濂?<c:param>??绛撅?濡???瑕?缁?瀵煎?ョ??璧?婧?浼??????幫???蹇?椤誨??rl灞??у?間腑璁劇疆濂借?浜????幫?杩??跺??浠ヤ嬌??lt;c:url>??绛炬?ュ??寤轟?涓?甯????扮??URL?闆??锛?姝ゆ?跺?????蹇?瑕?锛?<c:import>??绛懼????ゅ?煎?ヨ?婧?涓???????URL??????浜х????session id淇℃????

?

浣跨??lt;c:import>??绛懼?煎?ュ??ㄨ?婧???浠舵?訛?url灞??у??浠ヨ?劇疆涓鴻?瀵煎?ヨ?婧????稿??RL??缁?瀵?RL??

1锛?浣跨?ㄧ?稿??RL瀵煎?ュ?朵?璧?婧???浠?

锛?1锛?褰?琚?瀵煎?ョ??澶??ㄨ?婧???浠朵?褰???JSP??浠跺?浜???涓?涓?WEB搴??ㄧ?搴??訛?JSP瀹瑰?ㄥ?矽?婧?璺?寰???澶???涓?<jsp:include>??绛劇?稿??锛?杩??惰礬寰???浠ヤ互??/??瀛?绗??濮?锛?涔???浠ヤ互??浠跺??????褰???寮?濮???濡???璺?寰?浠モ??/??瀛?绗??濮?锛???琚?瀵煎?ヨ?婧???浠剁??璺?寰????稿?逛?JSP椤甸?㈡???ㄧ??WEB搴??ㄧ???矽礬寰?锛?濡???璺?寰?浠ユ??浠跺??????褰???寮?濮?锛???琚?瀵煎?ョ??璧?婧???浠剁??璺?寰?灏辨???稿?逛?褰?????JSP椤甸?㈢??璺?寰???

锛?2锛?褰?琚?瀵煎?ョ??澶??ㄨ?婧???浠朵?JSP??浠跺?浜???涓?涓????″?ㄤ???涓?????WEB搴??ㄦ?訛?濡???瑕?浣跨?ㄧ?稿?矽礬寰?锛?璺?寰?蹇?椤諱互??/??寮?濮???姝ゆ?訛?<c:import>??绛劇??context灞??у?椤昏?璁劇疆涓鴻?瀵煎?ョ??璧?婧???浠舵???ㄧ??WEB搴??ㄧ?搴?????绉般??娉ㄦ??锛?浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ?跺??WEB搴??ㄧ?搴?涓???璧?婧??訛?蹇?椤誨??lt;TOMCAT_HOME>\conf\server.xml??缃???浠朵腑灏?浣跨??lt;c:import>??绛劇??WEB搴??ㄧ?搴???<Context>??绱???crossContext灞??ц?劇疆涓?rue锛?濡?涓???绀猴?

<Context path="/JSTL"docBase="JSTL"crossContext="true"/>

2锛?浣跨?ㄧ?瀵?RL瀵煎?ュ?朵?璧?婧?

浣跨?ㄧ?瀵矽礬寰?瀵煎?ュ??ㄨ?婧???浠舵?訛??充嬌琚?瀵煎?ョ????浠朵?褰???JSP??浠跺?浜???涓?涓?WEB搴??ㄧ?搴?锛?琚?瀵煎?ョ??璧?婧???浠朵?涓?浼??變韓褰???JSP椤甸?㈢??request??session瀵矽薄????涓哄?ㄨ?绉????典?锛?褰???JSP??浠舵??灞???Web???″?ㄥ??褰?浜?涓?涓?Http瀹㈡?風??绋?搴?锛??昏?塊??缁?瀵矽礬寰?????瀹???澶??ㄨ?婧???浠訛??跺??灏???搴?缁?????瀹?浣???瀹瑰???ュ?闆???JSP椤甸??腑锛?姝ゆ?訛?璁塊??褰???JSP椤甸?㈢??瀹㈡?風????娴?瑙??????璁塊??缁?瀵矽礬寰?????瀹???澶??ㄨ?婧???浠剁??瀹㈡?風????褰???JSP??浠舵??灞???Web???″???杩??劇?跺?浜?涓や釜涓?????瀹㈡?風??锛???浠ワ?琚?瀵煎?ョ??璧?婧???浠跺??褰???JSP椤甸??????藉?變韓request??session瀵矽薄??

渚?绋?8-23??浣跨??lt;c:import>??绛劇??涓?涓?搴??ㄤ婦渚???

渚?绋?8-23 c_import.jsp

?

<%@ taglib prefix="c"uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ??涓?涓?WEB搴??ㄤ腑??璧?婧?:<br />

<c:importurl="/register.jsp?name=zhangsan">

??? <c:paramname="name" value="zxx" />

</c:import><hr/>

浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ??涓?涓????″?ㄤ???涓???WEB搴??ㄤ腑??璧?婧?:<br />

<c:importurl="/hello.jsp" context="/EL" /><hr />

浣跨?ㄧ?瀵矽礬寰?瀵煎?ヨ?婧?绀轟?1:

<c:importurl="http://localhost:8080/EL/hello.jsp" /><hr />

浣跨?ㄧ?瀵矽礬寰?瀵煎?ヨ?婧?绀轟?2:

<c:importurl="http://localhost:8080/JSTL/register.jsp"var="myImport"

??????????? charEncoding="gb2312">

??? <c:paramname="name" value="${param.name}" />

??? <c:param name="country"value="涓??? />

</c:import>

${myImport}

?

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??渚?绋?8-23锛??惰?琛?缁???濡???.20 ??绀猴?

??? http://localhost:8080/JSTL/c_import.jsp?name=zxx&country=China

??.20

??lt;c:import>??绛句腑浣跨?ㄧ?稿?矽礬寰?瀵煎?ュ?朵?璧?婧??訛??跺伐浣?????涓?<jsp:include>??绛劇?稿??锛???浠ワ??ㄨ?瀵煎?ョ??璧?婧???浠朵腑??浠ヨ?峰?浼???缁?褰???JSP椤甸?㈢??璇鋒????幫?渚?濡?锛?渚?绋?8-23涓???绗?涓?涓?<c:import>??绛懼苟娌℃???ㄧ????url??澧???country???幫?浣???锛???egister.jsp椤甸??腑?峰?浜?country???般??

8.3.13? <c:redirect>??绛?/h3>

<c:redirect>??绛劇?ㄤ?灏?褰?????璁塊??璇鋒?杞???????瀹????闆?朵?璧?婧?锛?瀹???浠ユ?規??url灞??ф????瀹????闆??锛??ц?绫諱技<jsp:forward>杩?涓?JSP??????绛劇?????斤?灏?璁塊??璇鋒?杞????闆?朵?璧?婧?锛????ц?response.sendRedirect()?規??????斤?灏?璁塊??璇鋒???瀹????闆?朵?璧?婧???<c:redirect>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<c:redirect url="value" [context="context"] />

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹???瀹????剁?????幫?

<c:redirect url="value" [context="context"]>

??? <c:param>subtags

</c:redirect>

<c:redirect>??绛劇??灞??ц?存??濡?琛?.11??绀恒??

琛?.11? <c:redirect>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
url true String ??瀹?瑕?杞???????瀹????扮??????璧?婧???URL?闆??
context true String 褰?瑕?浣跨?ㄧ?稿?矽礬寰???瀹????闆??涓?涓????″?ㄤ????朵?WEB搴??ㄧ?搴?涓???璧?婧??訛?context灞??ф??瀹??朵?WEB搴??ㄧ?搴?????绉?

?

url灞??ф??瀹?灏?瑕???瀹?????璧?婧???URL?訛???浠ヤ嬌?ㄧ?稿?矽礬寰???缁?瀵矽礬寰?锛??跺?蜂?缁???涓?<c:import>??绛劇??url灞??х?稿????渚?绋?8-24??涓?涓?浣跨??lt;c:redirect>??绛劇??搴??ㄤ?瀛???

渚?绋?8-24 c_redirect.jsp

?

<%@ taglibprefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<c:urlvalue="http://localhost:8080/JSTL/URL/register.jsp"var="myUrl">

??? <c:param name="name" value="寮?涓?" />

??? <c:param name="country" value="涓??? />

</c:url>

<c:redirecturl="${myUrl}" />

?

渚?绋?8-24??杩?琛?缁???濡???.21 ??绀恒??

??.21

8.4??介??????绛?/h2>

8.4.1 ??介??????绛懼?姒?杩?/h3>

涓轟?绠???WEB搴??ㄧ???介????寮???锛?JSTL涓???渚?浜?涓?涓??ㄤ?瀹??闆?介???????煎??????界????绛懼?锛???浠?灏??剁??绉頒負?介??????绛懼?锛?JSP瑙???涓哄?介??????绛懼?寤鴻??????缂???涓?mt???介??????绛懼?涓?????浜?涓?缁??ㄤ?瀹???EB?介???????界????绛撅?杩?缁???绛懼?瑁?浜?Java璇?瑷?涓?java.util??java.text杩?涓や釜??涓?涓??介?????稿?崇??API绫葷?????姐???介??????绛懼?涓???渚?浜?缁?瀹?璧?婧?????浠?璧?婧???涓??????拌?婧???浠跺??璇誨????????瀹圭????绛撅?涔???渚?浜?瀵規?闆?煎???ユ??绛????版???????版???????闆??淇℃??杩?琛??劇ず??瑙f??????绛撅?杩???渚?浜??????扮?瑰?????跺?烘?ヨ??存?堕?寸????绛俱??

?介??????绛懼?涓?????绛懼??浠ユ?規??瀹㈡?風??娴?瑙??ㄧ??淇℃???ヨ???ㄧ‘瀹????頒俊??锛?涔???浠ョ??SP椤甸??????懼??版??瀹????頒俊????濡???娌℃???瑰????瀹?锛???绔?妗?渚???璁鵑?璁ょ?????頒俊??涓衡??涓???锛?涓??斤?????

?ㄤ婦渚?璁茶В?介??????绛懼?涓?????绛炬?訛? ??甯歌?浣跨?ㄥ?闆??????澶?涓?璧?婧???浠剁??璧?婧???锛?杩?涓?璧?婧???涓?????涓?璧?婧???浠跺????瀵瑰???涓?涓??????頒俊????杩???????寤哄ソ涓?缁?璧?婧?????浠躲??棣?????渚?绋?8-25??渚?绋?8-26??寤轟袱涓???绉闆????涓?reetings.properties??temp.properties??璧?婧???浠躲??

渚?绋?8-25 greetings.properties

?

org.it315.heading=Thefirst WEB application

org.it315.welcome=Welcometo www.it315.org !

org.it315.okKey=Todayis {0,date,full}, you have {1,number,currency} dollars.

?

渚?绋?8-26 temp.properties

?

org.it315.heading=绗?涓?涓?WEB搴??ㄧ?搴?

org.it315.welcome=娆㈣?璁塊??www.it315.org缃?绔?!

org.it315.okKey=浠?澶╂??{0,date,full}锛?浣???{1,number,currency}????

?

?ョ??浣跨??DK涓???渚???native2ascii绋?搴?灏?temp.properties??浠朵腑??涓???瀛?绗?漿?㈡????nicode??褰㈠???杞?涔?搴??????ㄥ?戒護琛?绐??d腑杩???emp.properties??浠舵???ㄧ????褰?锛??ц?濡?涓??戒護锛?

?????? native2ascii -encoding GB2312temp.properties greetings_zh.properties

涓??㈢???戒護?ц???浜х????greetings_zh.properties??浠跺??瀹瑰?渚?绋?8-27??绀恒??

渚?绋?8-27 greetings_zh.properties

?

org.it315.heading=\u7b2c\u4e00\u4e2aWEB\u5e94\u7528\u7a0b\u5e8f

org.it315.welcome=\u6b22\u8fce\u8bbf\u95eewww.it315.org\u7f51\u7ad9!

org.it315.okKey=\u4eca\u5929\u662f{0,date,full}\uff0c\u4f60\u6709{1,number,

currency}\u5143\u3002

?

?辨?????扮??澧???瀵瑰???璧?婧???浠跺????澶???reetings.properties??浠訛?骞舵?瑰??涓?reetings_en.properties?沖????????灏?greetings.properties??greetings_en.properties??greetings_zh.properties杩?涓?涓?璧?婧???浠朵?瀛???lt;TOMCAT_HOME>\webapps\JSTL\WEB-INF\classes\org\it315\??褰?涓???

8.4.2 ?<fmt:setLocale>??绛?/h3>

<fmt:setLocale>??绛劇?ㄤ???SP椤甸??腑?懼??拌?劇疆?ㄦ?風?????闆??淇℃??锛?骞跺?璁劇疆?????闆??淇℃??浠?ocale瀵矽薄??褰㈠?淇?瀛??ㄦ??涓?Web??涓?锛??跺??eb??涓???灞??у??绉頒負??javax.servlet.jsp.jstl.fmt.locale????浣跨??lt;fmt:setLocale>??绛捐?劇疆???闆??淇℃????锛??介??????绛懼?涓????朵???绛懼?浣跨?ㄨ?ユ???闆??淇℃??锛???蹇界?ュ?㈡?風??娴?瑙??ㄤ???杩??ョ?????頒俊????<fmt:setLocale>??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:setLocalevalue="locale"

???????????????????? [variant="variant"]

???????????????????? [scope="{page|request|session|application}"]/>

<fmt:setLocale>??绛劇??灞??ц?存??濡?琛?.12??绀恒??

琛?.12? <fmt:setLocale>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true String??java.util.Locale ??瀹??ㄦ?風?????闆??淇℃??锛???浠ユ??涓?涓?瀛?绗?覆??java.util.Locale瀹?渚?瀵矽薄??濡?????瀛?绗?覆锛???蹇?椤誨????灏???褰㈠???璇?瑷?缂???锛??跺??涔???浠ュ甫??澶у??褰㈠????藉?剁???锛?涓よ??涓??寸?ㄢ??-??????_??杩???
variant true String ??瀹???寤?ocale瀹?渚?瀵矽薄?惰?劇疆???????ㄥ??锛?瀹??ㄤ???璇?寮????????瑰??娴?瑙??ㄤ負瀹??版?╁????借????瀹?涔???淇℃??
scope false String ??瀹?灏??????虹??Locale瀹?渚?瀵矽薄淇?瀛??ㄥ??涓?Web浣??ㄥ??涓?

濡???<fmt:setLocale>??绛劇??value灞??у?間負null锛?<fmt:setLocale>??绛懼????ㄥ?㈡?風??娴?瑙??ㄤ???杩??ョ?????頒俊????渚?绋?8-28??涓?涓?浣跨??lt;fmt:setLocale>??绛劇??渚?瀛?绋?搴???

渚?绋?8-28 fmt_setLocale.jsp

?

<%@ taglibprefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<fmt:setLocalevalue="${param.locale}" />

<fmt:setBundlebasename="org.it315.greetings" var="greetings" />

<head>

?????? <title><fmt:messagebundle="${greetings}" key="org.it315.heading"/></title>

</head>

<jsp:useBeanid="now" class="java.util.Date" />

<%

?????? session.setAttribute("number",new Integer(8888888));

%>

<fmt:messagebundle="${greetings}" key="org.it315.welcome" /><br/>

<fmt:messagebundle="${greetings}" key="org.it315.okKey">

?????? <fmt:param value="${now}"/>

?????? <fmt:param value="${number}"/>

</fmt:message>

?

渚?绋?8-28涓???<fmt:setBundle>??绛劇?ㄤ??規??<fmt:setLocale>??绛捐?劇疆?????闆??淇℃??缁?瀹?涓?涓?璧?婧???锛??剁???璇峰????8.4.3??锛?<fmt:message>??绛劇?ㄤ?浠?涓?涓?璧?婧???涓?璇誨??淇℃??骞惰?琛??煎???杈??猴??剁???璇峰????8.4.5??锛?<fmt:param>??绛劇?ㄤ?涓烘?煎???????涓蹭腑????浣?绗??劇疆???闆?鹼??剁???璇峰????8.4.6????

?ㄦ?瑙??ㄥ?闆????杈??ュ?涓??闆??璁塊??fmt_setLocale.jsp椤甸???

http://localhost:8080/JSTL/fmt_setLocale.jsp?locale=en_US

渚?绋?8-28??杩?琛?缁???濡???.22??绀恒??

??.22

灏?涓??㈢??璁塊???闆??涓???locale???拌?劇疆涓?h_CN??璁塊??fmt_setLocale.jsp椤甸???渚?绋?8-28??杩?琛?缁???濡???.23??绀恒??

??.23

8.4.3? <fmt:setBundle>??绛?/h3>

<fmt:setBundle>??绛劇?ㄤ??規??<fmt:setLocale>??绛捐?劇疆?????闆??淇℃????寤轟?涓?璧?婧???锛?ResourceBundle锛?瀹?渚?瀵矽薄锛?骞跺??剁?瀹??頒?涓?Web????灞??т???<fmt:setBundle>??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:setBundle basename="basename"

??????????? [var="varName"]

??????????? [scope="{page|request|session|application}"] />

<fmt:setBundle>??绛劇??灞??ц?存??濡?琛?.13??绀恒??

琛?.13? <fmt:setBundle>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
basename true String ??瀹???寤?esourceBundle瀹?渚?瀵矽薄???哄??
var false String ??瀹?灏???寤哄?虹??ResourceBundle瀹?渚?瀵矽薄淇?瀛???eb??涓???灞??у??绉?
scope false String ??瀹?灏???寤哄?虹??ResourceBundle瀹?渚?瀵矽薄淇?瀛??ㄥ??涓?Web浣??ㄥ??涓?

<fmt:setBundle>??绛炬??濡?涓?涓?浜??規?э?

锛?1锛?濡???basename灞??х???間負null??绌哄??绗?覆锛????句???asename灞??ф??瀹???璧?婧?锛?<fmt:setBundle>??绛句?瀛???eb??涓???灞??х???間負null??

锛?2锛?濡?????瀹?浜?var灞??э?<fmt:setBundle>??绛懼???ResourceBundle瀹?渚?瀵矽薄浠?ar灞??х???間?涓哄??灞??у??绉頒?瀛???eb??涓???

锛?3锛?濡???娌℃????瀹?var灞??э?<fmt:setBundle>??绛懼???ResourceBundle瀹?渚?瀵矽薄浠ュ??灞??у??javax.servlet.jsp.jstl.fmt.localizationContext淇?瀛???eb??涓???????娌℃??宓?濂???lt;fmt:bundle>??绛句腑涓?????瀹?bundle灞??х??<fmt:formatDate>?藉?浣跨?ㄨ?ユ??绛懼??寤虹??璧?婧?????

?ㄥ???㈢??渚?绋?8-28涓?宸茬?浣跨?ㄤ?<fmt:setBundle>??绛撅?杩???灏變???瀵?lt;fmt:setBundle>??绛捐?琛?涓句?璁茶В浜???

8.4.4? <fmt:bundle>??绛?/h3>

<fmt:bundle>??绛句?<fmt:setBundle>??绛劇?????界被浼鹼?浣?瀹???寤虹??ResourceBundle瀹?渚?瀵矽薄???ㄥ?舵??绛句?????????<fmt:bundle>??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:bundle basename="basename"

??????? [prefix="prefix"]>

??? body content

</fmt:bundle>

<fmt:bundle>??绛劇??灞??ц?存??濡?琛?.14??绀恒??

琛?.14? <fmt:bundle>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
basename true String ??瀹???寤?esourceBundle瀹?渚?瀵矽薄???哄??
prefix true String ??瀹?杩藉???闆?濂???lt;fmt:bundle>??绛懼????<fmt:message>??绛劇??key灞??у?煎???㈢????缂?

濡???璁劇疆浜?<fmt:bundle>??绛劇??prefix灞??э????朵腑宓?濂???<fmt:message>??绛劇??key灞??у?間腑灏卞??浠ョ????refix灞??ц?劇疆????缂??ㄥ??锛?杩?瀵矽?浣跨?ㄥ?鋒???稿????缂???澶?涓??抽??瀛??????墊??渚?浜?涓?浜?绠?渚褲??

渚?绋?8-29??涓?涓?浣跨??lt;fmt:bundle>??绛劇??渚?瀛?绋?搴?锛??朵腑????婕?绀轟?璁劇疆??涓?璁劇疆prefix灞??х?????點??

渚?绋?8-29 fmt_bundle.jsp

?

<%@ taglibprefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

娌℃??璁劇疆prefix灞??х??????<br />

<fmt:bundlebasename="org.it315.greetings">

?????? <fmt:messagekey="org.it315.heading" /><br />

?????? <fmt:message key="org.it315.welcome"/><br /><hr />

</fmt:bundle>

璁劇疆prefix灞??х??????<br />

<fmt:bundlebasename="org.it315.greetings" prefix="org.it315.">

?????? <fmt:message key="heading"/><br />

?????? <fmt:message key="welcome"/>

</fmt:bundle>

?

渚?绋?8-29??杩?琛?缁???濡???.24??绀恒??

??.24

8.4.5 ?<fmt:message>??绛?/h3>

<fmt:message>??绛劇?ㄤ?浠?涓?涓?璧?婧???涓?璇誨??淇℃??骞惰?琛??煎???杈??猴?瀹???濡?涓?涓?浜?浣跨?ㄨ??娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<fmt:message key="messageKey"??

??????????? [bundle="resourceBundle"]

??????????? [var="varName"]

??????????? [scope="{page|request|session|application}"] />

璇?娉?2锛??ㄦ??绛句?涓???瀹??煎???????涓蹭腑????浣?绗????扮?????碉?

<fmt:message key="messageKey"

??????????? [bundle="resourceBundle"]

??????????? [var="varName"]

??????????? [scope="{page|request|session|application}"]>

??? <fmt:param>subtags

</fmt:message>

璇?娉?3锛??ㄦ??绛句?涓???瀹?娑????抽??瀛????????╃????浣?绗????幫?

<fmt:message [bundle="resourceBundle"]

??????????? [var="varName"]

??????????? [scope="{page|request|session|application}"]>

??? key

??? optional<fmt:param>subtags

</fmt:message>

<fmt:message>??绛劇??灞??ц?存??濡?琛?.15??绀恒??

琛?.15? <fmt:message>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
key true String ??瀹?瑕?杈??虹??淇℃?????抽??瀛?
bundle true LocalizationContext ??瀹?ResourceBundle瀵矽薄??eb??涓???灞??у??绉?
var false String ?ㄤ???瀹?灏??煎???缁???淇?瀛??版??涓?Web??涓?????涓?灞??х????绉?
scope false String ??瀹?灏??煎???缁???淇?瀛??闆??涓?Web??涓?

<fmt:message>??绛炬??濡?涓?涓?浜??規?э?

l?濡?????瀹???璧?婧?涓?瀛????杈??衡?????<key>?????褰㈠?????璇?淇℃????

l?濡???ResouceBundle涓?涓?瀛???ey灞??ф??瀹???淇℃??锛?杈??衡?????<key>?????褰㈠?????璇?淇℃????

l?濡???key灞??х???間負null??绌哄??绗?覆锛?杈??衡??????????褰㈠?????璇?淇℃????

l?濡???娌℃????瀹?var灞??э?<fmt:message>??绛懼??存?ヨ??烘?煎?????缁???锛?濡?????瀹?浜?var灞??э???<fmt:message>??绛懼??煎?????缁???淇?瀛???cope灞??ф??瀹???Web??涓?锛?淇?瀛???eb??涓???灞??у??绉頒負var灞??ф??瀹????箋??濡?????瀹?浜?scope灞??э?灏卞?椤繪??瀹?var灞??с??

l?瑕?杈??虹??娑??????抽??瀛???浠ヤ嬌??ey灞??ф??瀹?锛?涔???浠ュ?ㄦ??绛句?涓???瀹???濡???<fmt:message>??绛懼?濂???lt;fmt:bundle>??绛懼??锛?骞朵?<fmt:bundle>??绛捐?劇疆浜?prefix灞??э???璇ュ??х???艱拷????lt;fmt:message>??绛炬??瀹????抽??瀛?????????

l???浠ラ??杩???lt;fmt:message>??绛懼??宓?濂?<fmt:param>??绛炬?ユ??瀹??煎???????涓蹭腑????浣?绗??????闆?鹼?姣?涓?<fmt:param>??绛懼????璁劇疆涓?涓????幫???涓?<fmt:param>??绛劇??椤哄?涓??煎???瀛?绗?覆?????扮?稿?瑰?锛??崇??涓?涓?<fmt:param>??绛懼?瑰?浜??煎???瀛?绗?覆涓???绗?涓?涓????幫?绗?浜?涓?<fmt:param>瀵瑰?浜??煎???瀛?绗?覆涓???绗?浜?涓????幫?渚?娆$被?ㄣ??

l?濡???<fmt:message>??绛懼??????煎???????涓蹭腑?????????幫?浣??朵腑娌℃??宓?濂?涓?璇ュ???闆?瑰?<fmt:param>??绛撅????存?ヨ??鴻?ュ???闆?ㄦ?煎???????涓蹭腑????濮?褰㈠???

?

渚?绋?8-30??涓?涓?浣跨??lt;fmt:message>??绛劇??渚?瀛?绋?搴???

渚?绋?8-30? fmt_message.jsp

?

<%@ taglibprefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<jsp:useBeanid="now" class="java.util.Date" />

<%

?????? session.setAttribute("number",new Integer(8888888));

%>

<fmt:setBundlebasename="org.it315.greetings" var="greetings" />

&lt;fmt:message&gt;??绛懼??宓?濂?&lt;fmt:param&gt;??绛劇?????碉?<br />

<fmt:messagebundle="${greetings}">

?????? org.it315.okKey

?????? <fmt:param value="${now}"/>

?????? <fmt:param value="${number}"/>

</fmt:message><br/><hr />

&lt;fmt:message&gt;??绛懼??娌℃??宓?濂?&lt;fmt:param&gt;??绛劇?????碉?<br />

<fmt:bundlebasename="org.it315.greetings" prefix="org.it315.">

?????? <fmt:message key="okKey"/>

</fmt:bundle>?????

?

渚?绋?8-30??杩?琛?缁???濡???.25 ??绀恒??

??.25

8.4.6 ?<fmt:param>??绛?/h3>

<fmt:param>??绛劇?ㄤ?涓烘?煎???????涓蹭腑????浣?绗??劇疆???闆?鹼?瀹????藉?濂???lt;fmt:message>??绛懼??浣跨?ㄣ??<fmt:param>??绛炬??濡?涓?涓ょ?璇?娉??煎?锛?

璇?娉?1锛???alue灞??ф??瀹????闆?鹼?

<fmt:param value="messageParameter" />

璇?娉?2锛??ㄦ??绛句?涓???瀹????扮???肩?????碉?

<fmt:param>

??? body content

</fmt:param>

璇存??锛?<fmt:param>??绛劇??value灞??х??绫誨????java.lang.Object锛?瀹??????ㄦ??灞??у?箋???ㄥ???㈢??渚?绋?涓?宸茬?澶?娆′嬌?ㄤ?<fmt:param>??绛撅?杩???灏變???瀵?lt;fmt:param>??绛捐?琛?涓句?璁茶В浜???

8.4.7 ?<fmt:requestEncoding>??绛?/h3>

<fmt:requestEncoding>??绛劇?ㄤ?璁劇疆璇鋒?娑?????瀛?绗???缂???锛?璇ユ??绛懼???ㄨ???equest.setCharacterEncoding()?規?锛?浠ヤ究Web瀹瑰?ㄥ?璇鋒?娑???涓??????闆?兼??璇ュ??绗???缂???杞??㈡??Unicode瀛?绗?覆杩?????<fmt:requestEncoding>??绛劇??璇?娉??煎?濡?涓?锛?

??? <fmt:requestEncoding[value="charsetName" />

?朵腑??value灞??х?ㄤ???瀹?璇鋒?娑?????瀛?绗???缂???锛??剁被??涓?tring锛??????ㄦ??灞??у?箋??

?充?<fmt:requestEncoding>??绛劇?????矽?存??锛?

锛?1锛?涓轟??藉?姝g‘瑙g??璇鋒????闆?間腑????ISO-8859-1缂?????瀛?绗??搴?璇ヨ??ㄨ?涓???绛炬?ヨ?劇疆璇鋒?娑?????瀛?绗???缂???锛?骞朵?蹇?椤誨?ㄨ?峰??浠諱?璇鋒????幫?????浣跨??L琛ㄨ揪寮??峰?????幫?涔???杩?琛?璋??ㄣ??

锛?2锛???涓哄?澶?娴?瑙??ㄦ病??瀹??ㄩ?靛??HTTP瑙???锛??ㄨ?鋒?娑???涓?娌℃??????Content-Type璇鋒?澶達???浠ヤ嬌?ㄨ?涓???绛炬?ヨ?劇疆璇鋒?娑?????瀛?绗???缂?????寰???蹇?瑕?????

锛?3锛?<fmt:requestEncoding>??绛劇??value灞??х??璁劇疆?奸??甯鎬負??浜よ?娆¤?鋒???椤甸?㈢??瀛?绗???缂???锛?濡???涓??介???纭?瀹?璇鋒?娑?????瀛?绗???缂???锛??e氨涓?搴???瀹?value灞??с??濡???娌℃??璁劇疆<fmt:requestEncoding>??绛劇??value灞??э?<fmt:requestEncoding>??绛鵑??????ㄨ?鋒?娑?????Content-Type澶翠腑瀹?涔???瀛?绗???缂???锛?濡???涓??戒?璇鋒?娑?????Content-Type澶翠腑纭?瀹?瀛?绗???缂???锛???????ession??涓???javax.servlet.jsp.jstl.fmt.request.charset灞??х???鹼?????锛?????SO-8859-1瀛?绗???缂?????

渚?绋?8-31??涓?涓?浣跨??lt;fmt:requestEncoding>??绛劇??渚?瀛?绋?搴???

渚?绋?8-31 fmt_requestEncoding.jsp

?

<%@ taglibprefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ pagecontentType="text/html;charset=gb2312" %>

<fmt:requestEncodingvalue="gb2312" />

??? ??????娆㈢??绉?????:${param.favourite}<br />

<formmethod="POST">

??? 浣?????娆㈠???????浠?涔?绉????<br />

??? <input type="text" name="favourite" />

??? <input type="submit" value="OK"/><br/>

</form>

?

渚?绋?8-31??杩?琛?缁???濡???.26??绀猴??ㄦ????妗?涓?杈??モ???辮????锛????誨?朵腑??OK????????杩?琛?缁???濡???.27??绀恒??

??.26

??.27

8.4.8 ?<fmt:timeZone>??绛?/h3>

<fmt:timeZone>??绛劇?ㄤ?璁劇疆?跺?猴?浣?瀹???璁劇疆?煎??瀵瑰?舵??绛句??ㄥ????????<fmt:timeZone>??绛炬??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:timeZonevalue="timeZone">

?????? bodycontent

</fmt:timeZone>

?朵腑??value灞??ф?????ㄦ??灞??у?鹼?瀹????煎??浠ユ??涓?涓??藉???跺?虹??瀛?绗?覆锛?涔???浠ユ??java.util.TimeZone绫葷??涓?涓?瀹?渚?瀵矽薄??濡???value灞??х???間負null??绌哄??绗?覆锛???绛句?涓?????瀹瑰氨浣跨??MT??0?哄???跺?恒??濡???value灞??х???兼??琛ㄧず?跺?哄??绉扮??瀛?绗?覆锛?杩?涓?瀛?绗?覆??杩?java.util.TimeZone.getTimeZone()?????規?琚?瑙f??涓?ava.util.TimeZone绫葷??瀹?渚?瀵矽薄??

渚?绋?8-32??涓?涓?浣跨??lt;fmt:timeZone>??绛劇??渚?瀛?绋?搴???

渚?绋?8-32 fmt_timeZone.jsp

?

<%@ taglib prefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=gb2312" %>

<%@ page import="java.util.TimeZone" %>

<jsp:useBean id="now" class="java.util.Date"/>

浣跨?ㄢ??GMT+1:00???跺?猴?<br/>

<fmt:timeZone value="GMT+1:00">

?????? <fmt:formatDatevalue="${now}" type="both" dateStyle="full"timeStyle="full"/>

</fmt:timeZone><br /><hr />

<%

?????? TimeZone tz =TimeZone.getDefault();

?????? pageContext.setAttribute("tz",tz);

%>

浣跨?ㄩ?璁ょ???跺?猴?value涓?ava.util.TimeZone??涓?涓?瀹?渚?锛?<br/>

<fmt:timeZone value="${tz}">

?????? <fmt:formatDatevalue="${now}" type="both" dateStyle="full"timeStyle="full"/>

</fmt:timeZone><br /><hr />

浣跨?ㄢ??America/Los_Angeles???跺?猴?<br/>

<fmt:timeZone value="America/Los_Angeles">

?????? <fmt:formatDatevalue="${now}" type="both" dateStyle="full"timeStyle="full"/>

</fmt:timeZone>

?

渚?绋?8-32??杩?琛?缁???濡???.28 ??绀恒??

??.28

8.4.9? <fmt:setTimeZone>

<fmt:setTimeZone>??绛劇?ㄤ???SP椤甸??腑?劇ず?拌?劇疆?跺?猴?骞跺?璁劇疆???跺?轟俊??浠?imeZone瀵矽薄??褰㈠?淇?瀛??ㄦ??涓?Web??涓?锛??跺??eb??涓???灞??у??绉頒負javax.servlet.jsp.jstl.fmt.timeZone??<fmt:setTimeZone>??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:setTimeZonevalue="timeZone"

??????????? ??? [var="varName"]

??????????? ??? [scope="{page|request|session|application}"]/>

<fmt:setTimeZone>??绛劇??灞??ц?存??濡?琛?.16??绀恒??

琛?.16? <fmt:setTimeZone>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true String??java.util.TimeZone ??瀹?琛ㄧず?跺?虹??ID瀛?绗?覆??TimeZone瀵矽薄
var false String ??瀹?灏???寤哄?虹??TimeZone瀹?渚?瀵矽薄淇?瀛???eb??涓???灞??у??绉?
scope false String ??瀹?灏???寤哄?虹??TimeZone瀹?渚?瀵矽薄淇?瀛??闆??涓?Web??涓?

?朵腑锛?value灞??х??璁劇疆?肩??缁???涓?<fmt:timeZone>??绛劇??缁????稿??锛?<fmt:setTimeZone>??绛懼???寤哄?虹??TimeZone瀹?渚?瀵矽薄淇?瀛???cope灞??ф??瀹???Web??涓?锛?濡?????瀹?浜?var灞??э?淇?瀛???eb??涓???灞??у??绉頒負var灞??ф??瀹????鹼?????锛?淇?瀛???eb??涓???灞??у??绉頒負javax.servlet.jsp.jstl.fmt.timeZone锛?????娌℃??宓?濂??ㄥ?朵?<fmt:timeZone>??绛句腑涓?????瀹?timezone灞??х??<fmt:formatDate>??绛鵑?藉?浣跨?ㄨ?ュ??灞??у???寵?????跺?恒??

渚?绋?8-33??涓?涓?浣跨??lt;fmt:setTimeZone>??绛劇??渚?瀛?绋?搴???

渚?绋?8-33 fmt_setTimeZone.jsp

?

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>

<%@ page contentType="text/html;charset=gb2312" %>

<jsp:useBean id="now" class="java.util.Date"/>

<fmt:setTimeZone value="America/Los_Angeles"/>

??America/Los_Angeles???跺?虹???闆?ㄦ?堕?存??:<br/>

<fmt:formatDate value="${now}" type="both"/><hr />

??GMT+1:00???跺?虹???闆?ㄦ?堕?存??:<br />

<fmt:timeZone value="GMT+1:00">

?????? <fmt:formatDatevalue="${now}" type="both" />

</fmt:timeZone>

?

渚?绋?8-33??杩?琛?缁???濡???.29??绀恒??

??.29

8.4.10? <fmt:formatDate>??绛?/h3>

<fmt:formatDate>??绛劇?ㄤ?瀵規?ユ?????堕?存?????闆??淇℃??杩?琛??煎???锛???瀵規?ユ?????堕?存????涓?SP椤甸???????瀹?涔????煎?杩?琛??煎?????<fmt:formatDate>??绛劇??璇?娉??煎?濡?涓?锛?

<fmt:formatDatevalue="date"???

??????????????? [type="{time|date|both}"]

??????????????? [dateStyle="{default|short|medium|long|full}"]

??????????????? [timeStyle="{default|short|medium|long|full}"]

??????????????? [pattern="customPattern"]

??????????????? [timeZone="timeZone"]

??????????????? [var="varName"]

??????????????? [scope="{page|request|session|application}"]/>

<fmt:formatDate>??绛劇??灞??ц?存??濡?琛?.17??绀恒??

琛?.17<fmt:formatDate>??绛劇??灞???

灞??у?? ????????EL 灞??х被?? 灞? ???? 杩?
value true java.util.Date ??瀹?瑕??煎??????ユ?????堕??
type true String ??瀹????煎???杈??烘?ユ???ㄥ??锛?杩????煎???杈??烘?堕?撮?ㄥ??锛?杩???涓よ???借???
dateStyle true String ??瀹??ユ???ㄥ????杈??烘?煎?锛??跺???ㄧ??璁劇疆?煎??浠ュ????ava.text.DateFormat绫葷??璁茶В??璇ュ??т???ype灞??у???間負date??both?舵??????
timeStyle true String ??瀹??堕?撮?ㄥ????杈??烘?煎?锛??跺???ㄧ??璁劇疆?艱?峰????ava.text.DateFormat绫葷??璁茶В??璇ュ??т???ype灞??у???間負time??both?舵??????
pattern true String ??瀹?涓?涓???瀹?涔????ユ?????堕?磋??烘?煎?
timeZone true String??java.util.timeZone ??瀹?褰??????ㄧ???跺??
var false String ?ㄤ???瀹?灏??煎???缁???淇?瀛??版??涓?Web??涓?????涓?灞??х????绉?
scope false String ??瀹?灏??煎???缁???淇?瀛??闆??涓?Web??涓?

?

<fmt:formatDate>??绛炬??濡?涓?涓?浜??規?э?

l? 濡???娌℃????瀹?var灞??э?<fmt: formatDate>??绛懼??存?ヨ??烘?煎?????缁???锛?濡?????瀹?浜?var灞??э???<fmt:formatDate>??绛懼??煎?????缁???淇?瀛???cope灞??ф??瀹???Web??涓?锛?淇?瀛???eb??涓???灞??у??绉頒負var灞??ф??瀹????箋??濡?????瀹?浜?scope灞??э?灏卞?椤繪??瀹?var灞??с??

l?濡???value灞??х???間負null锛???涓?杈??轟換浣???瀹癸?濡???杩??跺????瀹?浜?var??scope灞??э?灏?scope灞??ф??瀹???Web??涓???var灞??ф??瀹?????灞??у???ゃ??

l? JSP缃?椤典?????浠ヤ嬌??attern灞??ц?劇疆??瀹?涔????ユ???煎?锛?杩??跺??锛?<fmt:formatDate>??绛懼?蹇界??ype??dateStyle??timeStyle绛?灞??с??pattern灞??х???煎?椤葷????java.text.SimpleDateFormat绫葷???ユ??妯″???璇?娉???

l?濡???timeZone灞??х???間負null????绌哄??绗?覆锛??稿?浜?娌℃??璁劇疆杩?涓?灞??с??

l?濡???瑕??煎???涓?涓?琛ㄧず?ユ?????堕?寸??瀛?绗?覆锛?蹇?椤婚?????lt;fmt:parseDate>??绛懼??惰В??涓?ava.util.Date绫葷??涓?涓?瀹?渚?瀵矽薄锛???浣跨??lt;fmt:formatDate >??绛懼?矽?涓?Date瀹?渚?瀵矽薄杩?琛??煎?????<fmt:parseDate>??绛劇??浠?缁?璇峰????8.4.11????

l?濡???<fmt:formatDate>??绛句??界‘瀹??煎????????闆??淇℃??锛?灏變嬌??ava.util.Date.toString()?規?浣?涓鴻??烘?煎???

渚?绋?8-34??涓?涓?浣跨??lt;fmt:formatDate>??绛劇??渚?瀛?绋?搴???

渚?绋?8-34 fmt_formatDate.jsp

?

<%@ taglib prefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=gb2312" %>

<%@ page import="java.util.TimeZone" %>

<jsp:useBean id="now" class="java.util.Date"/>

?煎???褰????ユ?????堕?達?

<fmt:formatDate value="${now}" type="both"timeStyle="medium" dateStyle="long"/>

<hr/>

<%

?????? session.setAttribute("tz",TimeZone.getTimeZone("GMT+10"));

%>

??瀹??跺?轟負??GMT+10??锛?

<fmt:formatDate value="${now}" type="both"timeZone="${tz}" /><hr />

??瀹???瀹?涔????煎?锛???.??骞?

<fmt:formatDate value="${now}"pattern="MM.dd.yyyy" /><hr />

?煎????ㄥ??绗?覆琛ㄧず???ユ??锛?

<fmt:parseDate value="7/31/05"pattern="MM/dd/yy" var="parsed" />

<fmt:formatDate value="${parsed}" />

?

渚?绋?8-34??杩?琛?缁???濡???.30 ??绀恒??

??.30

8.4.11? <fmt:parseDate>??绛?/h3>

<fmt:parseDate>??绛句?<fmt: formatDate>??绛劇??浣??ㄦ?eソ?稿??锛?瀹??ㄤ?灏?涓?涓?琛ㄧず?ユ?????堕?寸??瀛?绗?覆瑙f????java.util.Date瀹?渚?瀵矽薄锛?瀹???濡?涓?涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<fmt:parseDate value="dateString"

??????????????? [type="time|date|both"]

??????????????? [dateStyle="default|short|medium|long|full"]

??????????????? [timeStyle="default|short|medium|long|full"]

??????????????? [pattern="customPattern"]

??????????????? [timeZone="timeZone"]

??????????????? [parseLocale="parseLocale"]

??????????????? [var="varName"]

??????????????? [scope="{page|request|session|application}"]/>

璇?娉?2锛? ????绛句??????碉??ㄦ??绛句?涓???瀹?瑕?琚?瑙f?????ユ????/???堕?村?鹼?

<fmt:parseDate [type="time|date|both"]

??????????????? [dateStyle="default|short|medium|long|full"]

??????????????? [timeStyle="default|short|medium|long|full"]

??????????????? [pattern="customPattern"]

??????????????? [timeZone="timeZone"]

??????????????? [parseLocale="parseLocale"]

??????????????? [var="varName"]

??????????????? [scope="{page|request|session|application}"]>

??????? date value to be parsed

</fmt:parseDate>

<fmt:parseDate>??绛劇??灞??ц?存??濡?琛?.18??绀恒??

琛?.18 <fmt:parseDate>??绛劇??灞???

<fmt:parseDate>??绛炬??濡?涓?涓?浜??規?э?

l? value灞??х???煎?椤繪????娉????ユ??/?堕?村??绗?覆锛?????<fmt:parseDate>??绛懼?ㄨВ???舵???哄?甯搞??濡???value灞??х???間負null??绌哄??绗?覆锛?灏卞????cope灞??ф??瀹????????翠腑??var灞??у?藉??????????

l??規??type灞??х???鹼?瑕?瑙f???ユ??瀛?绗?覆??浠ュ?????ユ?????堕?存?????跺?????ユ?????堕?達?骞舵?規????瀹????煎?绫誨??杩?琛?瑙f????

l?濡???timeZone灞??х???間負null??绌哄??绗?覆锛???娌℃??璁劇疆杩?涓?灞??у?????

l? 濡???parseLocale灞??х???間負null??绌哄??绗?覆锛???娌℃??璁劇疆璇ュ??у?????

l?濡?????瀹?pattern灞??э???绛懼氨蹇界?ュ????type??dateStyle??timeStyle灞??с??杩??訛??規??pattern灞??ц?劇疆????瀹?涔??煎?瑙f??value灞??ф??瀹????ユ????/???堕?村??绗?覆锛???浠ワ?瑕?瑙f?????ユ????/???堕?村??绗?覆蹇?椤諱弗?肩????pattern灞??ц?劇疆????瀹?涔??煎???pattern灞??х???煎?椤葷????java.text.SimpleDateFormat绫葷??妯″?璇?娉???

l?濡?????绛句??界‘瀹?瑙f???????扮??澧?锛?灏辨????spException寮?甯革?寮?甯鎬俊??涓?????瑕?瑙f????瀛?绗?覆??

?

?ㄥ???㈢??渚?绋?8-34涓?宸茬?浣跨?ㄤ?<fmt:parseDate>??绛撅?杩???灏變???瀵?lt;fmt:parseDate>??绛捐?琛?涓句?璁茶В浜???

8.4.12? <fmt:formatNumber>??绛?/h3>

<fmt:formatNumber>??绛劇?ㄤ?灏??闆?箋??璐у????懼???版?????闆??淇℃??杩?琛??煎???锛???????JSP椤甸???????瀹?涔????煎?杩?琛??煎?????<fmt:formatNumber>??绛炬??涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<fmt:formatNumbervalue="numericValue"

??? ??? ??? ??? ?[type="{number|currency|percent}"]

??? ??? ??? ??? ?[pattern="customPattern"]

??? ??? ??? ??? ?[currencyCode="currencyCode"]

??? ??? ??? ??? ?[currencySymbol="currencySymbol"]

??? ??? ??? ??? ?[groupingUsed="{true|false}"]

??? ??? ??? ??? ?[maxIntegerDigits="maxIntegerDigits"]

??? ??? ??? ??? ?[minIntegerDigits="minIntegerDigits"]

??? ??? ??? ??? ?[maxFractionDigits="maxFractionDigits"]

??? ??? ??? ??? ?[minFractionDigits="minFractionDigits"]

??? ??? ??? ??? ?[var="varName"]

??? ??? ??? ??? ?[scope="{page|request|session|application}"]/>

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹?瑕?琚??煎??????闆?鹼?

<fmt:formatNumber[type="{number|currency|percent}"]

??? ??? ??? ??? ?[pattern="customPattern"]

??? ??? ??? ??? ?[currencyCode="currencyCode"]

??? ??? ??? ??? ?[currencySymbol="currencySymbol"]

??? ??? ??? ??? ?[groupingUsed="{true|false}"]

??? ??? ??? ??? ?[maxIntegerDigits="maxIntegerDigits"]

??? ??? ??? ??? ?[minIntegerDigits="minIntegerDigits"]

??? ??? ??? ??? ?[maxFractionDigits="maxFractionDigits"]

??? ??? ??? ??? ?[minFractionDigits="minFractionDigits"]

??? ??? ??? ??? ?[var="varName"]

??? ??? ??? ??? ?[scope="{page|request|session|application}"]>

??????? 瑕?琚??煎??????闆??

</fmt:formatNumber>

濡?????瀹?scope灞??э?灏卞?椤繪??瀹?var灞??с??<fmt:formatNumber>??绛劇??灞??ц?存??濡?琛?.19??绀恒??

琛?.19 <fmt:formatNumber>??绛劇??灞???

<fmt:formatNumber>??绛炬??濡?涓?涓?浜??規?э?

l?濡???value灞??х???間負null锛???涓?杈??轟換浣???瀹癸?濡???杩??跺????瀹?浜?var??scope灞??э?灏?scope灞??ф??瀹???Web??涓???var灞??ф??瀹?????灞??у???ゃ??

l?pattern灞??т???浜?type灞??э?涓?绠℃??浣跨?ㄥ??涓?灞??э??煎???????璁幫?渚?濡???杩??跺??扮???存?伴?ㄥ????灏??伴?ㄥ????????绗???缁?????绗????杩??煎?????Locale?規?ф?ュ?沖????

l?pattern灞??ф??瀹???妯″?瀛?绗?覆蹇?椤葷????java.text.DecimalFormat绫葷??妯″?璇?娉???濡???pattern灞??т負null??绌哄??绗?覆锛?灏辯?稿?浜?娌℃??璁劇疆杩?涓?灞??х???箋??

l?currencyCode灞??х???煎?椤繪??涓?涓???娉???ISO 4217璐у?缂?????

l?groupingUsed灞??ф??瀹??????灏??煎????????闆?肩???存?伴?ㄥ?????闆????缁???渚?濡?锛??ㄨ?辮?????扮??澧?涓?锛?灏?姣?杈?澶х???闆?兼??姣?涓?涓??闆????涓轟?缁?锛?姣?缁??ㄩ???峰????锛??跺???????扮??澧????界?ㄧ?規??绌烘?兼?ュ????杩??風????缁???璇??淇℃??????java.text.NumberFormat绫葷??setGroupingUsed()?規???

l?褰?type灞??х???間負currency?訛?currencyCode灞??х?ㄦ?ユ?懼??版??瀹?瑕??劇ず???版????璐у?绗??楓??currencySymbol灞??т???浠ユ?懼??版??瀹?璐у?绗??楓??褰?WEB瀹瑰?ㄧ??杩?琛???澧???JDK1.4???撮???????訛?濡??????舵??瀹?<fmt:formatNumber>??绛劇??currencyCode??currencySymbol灞??э?????浼???浜?????锛?浣?褰?WEB瀹瑰?ㄧ??杩?琛???澧???JDK1.4浠ュ?????????訛?currencySymbol灞??т???浜?currencyCode灞??с??

l?濡???<fmt:formatNumber>??绛句??界‘瀹??煎????????扮??澧?锛?灏變嬌??umber.toString()浣?涓鴻??烘?煎???

渚?绋?8-35??涓?涓?浣跨??lt;fmt:formatNumber>??绛劇??渚?瀛?绋?搴???

渚?绋?8-35? fmt_formatNumber.jsp

?

<%@ taglib prefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=gb2312"%>

<%@ pageimport="java.util.Currency,java.util.Locale"%>

灏??闆?兼?煎???涓鴻揣甯??煎?锛?

<fmt:formatNumbervalue="9876543.21" type="currency" /><hr />

灏??闆?兼?煎???涓虹?懼???版?煎?锛?

<fmt:formatNumber value="12.3"type="percent" /><hr />

灏??闆?兼?煎???涓鴻??瀹?涔????煎?锛?

<fmt:formatNumber value="12.3"pattern=".000" />锛?

<fmt:formatNumbervalue="123456.7891" pattern="#,#00.0#" /><hr />

<%

?????? Stringcode = Currency.getInstance(Locale.CHINA).getCurrencyCode();

?????? Stringsymbol = Currency.getInstance(Locale.US).getSymbol();

?????? session.setAttribute("code",code);

?????? session.setAttribute("symbol",symbol);

%>

???舵??瀹?currencyCode??currencySymbol灞??э?????浼???浜?????锛?

<fmt:formatNumbervalue="1234567.11" type="currency"currencyCode="${code}"

?????? currencySymbol="${symbol}"/>

?

渚?绋?8-35??杩?琛?缁???濡???.31??绀恒??

??.31

8.4.13? <fmt:parseNumber>??绛?/h3>

<fmt:parseDate>??绛句?<fmt: formatNumber>??绛劇??浣??ㄦ?eソ?稿??锛?瀹??ㄤ?灏?涓?涓??????闆???瑰?琚??煎????????闆?箋??璐у????懼???拌В??涓烘?闆?鹼?瀹???濡?涓?涓ょ?璇?娉??煎?锛?

璇?娉?1锛?娌℃????绛句??????碉?

<fmt:parseNumbervalue="numericValue"??

??????????????? [type="{number|currency|percent}"]

??????????????? [pattern="customPattern"]

??????????????? [parseLocale="parseLocale"]

??????????????? [integerOnly="{true|false}"]

??????????????? [var="varName"]

??????????????? [scope="{page|request|session|application}"]/>

璇?娉?2锛?????绛句??????碉??ㄦ??绛句?涓???瀹?瑕?琚?瑙f?????闆?鹼?

<fmt:parseNumber[type="{number|currency|percent}"]

??????????????? ?[pattern="customPattern"]

??????????????? ?[parseLocale="parseLocale"]

??????????? ??? ?[integerOnly="{true|false}"]

??????????????? ?[var="varName"]

??????????????? ?[scope="{page|request|session|application}"]>

??? numericvalue to be parsed

</fmt:parseNumber>

<fmt:parseNumber>??绛劇??灞??ц?存??濡?琛?.20??绀恒??

琛?.20 <fmt:parseNumber>??绛劇??灞???

<fmt:parseNumber>??绛炬??濡?涓?涓?浜??規?э?

l? 濡???value灞??х???間負null??绌哄??绗?覆锛???灏?scope灞??ф??瀹???Web??涓???var灞??ф??瀹?????灞??у???ゃ??濡???value灞??х???間??借В??涓烘?闆?煎氨???哄?甯搞??

l? pattern灞??ф??瀹???妯″?瀛?绗?覆蹇?椤葷????java.text.DecimalFormat绫葷??妯″?璇?娉???濡????跺?間負null??绌哄??绗?覆锛?灏辯?稿?浜?娌℃??璁劇疆杩?涓?灞??х???箋??浣跨??lt;fmt:parseNumber>瑙f???兼?惰??瑰??娉ㄦ??锛?瀹??ц???瑙f????甯鎬弗?鹼?瑕?瑙f?????闆?煎??绗?覆蹇?椤諱弗?肩?????瑰???????扮??澧???pattern灞??ц?劇疆????瀹?涔??煎???

l? 濡???parseLocale灞??х???間負null??绌哄??绗?覆锛?灏辯?稿?浜?娌℃????瀹?璇ュ??с??

l?integerOnly灞??ф??瀹?????????瑙f??value???存?伴?ㄥ????璇??淇℃??璇風??java.text.NumberFormat?ュ?g??setParseIntegerOnly()?規???

l?濡??????舵??瀹?type灞??у??pattern灞??э?????浼?????楂?浜???????

l?濡???璁劇疆浜?var灞??э?灏?瑙f????缁???淇?瀛??ㄦ??涓?Web??涓???var灞??ф??瀹?????灞??т腑锛?????锛?<fmt:parseNumber>灏?浣跨??ava.lang.Number.toString()?存?ヨ??鴻В????缁?????濡?????瀹?scope灞??э???蹇?椤繪??瀹?var灞??с??

l?濡?????绛句??界‘瀹?瑙f???????扮??澧?锛?灏辨????spException寮?甯革?寮?甯鎬俊??涓?????瑕?瑙f????瀛?绗?覆??

渚?绋?8-36??涓?涓?浣跨??lt;fmt:parseNumber>??绛劇??渚?瀛?绋?搴???

渚?绋?8-36 fmt_parseNumber.jsp

?

<%@ taglib prefix="fmt"uri="http://java.sun.com/jsp/jstl/fmt" %>

<%@ page contentType="text/html;charset=gb2312" %>

???扮??澧?涓衡??en_US??瑙f??瀛?绗?覆??$123,456,789.00??锛?

<fmt:parseNumber value="$123,456,789.00"type="currency" parseLocale="en_US"/>

<hr/>

瑙f???翠釜?闆?煎??绗?覆??123,456,789%??锛?

<fmt:parseNumber value="123,456,789%"type="percent" /><hr />

??瑙f????123,456,789%?????存?伴?ㄥ??锛?

<fmt:parseNumber value="123,456,789%" type="percent"integerOnly="true"/><hr />

???惰?劇疆type??pattern灞??э?????浼???浜?????锛?

<fmt:parseNumber value="12.3" type="currency"pattern=".000" />

?

渚?绋?8-36??杩?琛?缁???濡???.32 ??绀恒??

??.32

?

娉ㄦ??锛??ㄥ??灞?璁捐?$??杞?浠舵?舵??涓?锛?JSP椤甸?㈤??甯鎬??ㄤ?瀹??扮郴缁???琛ㄧず灞?锛??版??瑙f????浠誨?′??????ㄨ〃绀哄?杩?琛?澶???锛?????濂芥??涓??¢?昏?灞?杩?琛?澶???锛???浠ワ?涓轟?澧?寮鴻蔣浠剁????缁存?ゆ?у?????╁??э?璇昏??搴?灏介???垮????SP 椤甸??腑浣跨??lt;fmt:parseDate>??<fmt:parseNumber>??绛俱??

??.39

8.7? JSTL?芥??/h2>

涓轟?绠?????SP椤甸?㈡??浣?瀛?绗?覆锛?JSTL涓???渚?浜?涓?濂?EL??瀹?涔??芥?幫?杩?浜??芥?闆????浜?JSP椤甸?㈠?朵???缁?甯歌??ㄥ?扮??瀛?绗?覆??浣???渚?濡?锛?fn:toLowerCase灏?瀛?绗?覆涓???瀛?绗???涓哄???锛?fn:indexOf杩???涓?涓???瀹?瀛?绗?覆?ㄥ???涓?瀛?绗?覆涓?绗?涓?娆″?虹?扮??绱㈠?浣?缃???

JSTL涓???渚???EL??瀹?涔??芥?闆?椤誨??L琛ㄨ揪寮?涓?浣跨???渚?濡?锛?${fn:toUpperCase("www.it315.org")}??

8.7.1? fn:toLowerCase?芥??/h3>

fn:toLowerCase?芥?闆?涓?涓?瀛?绗?覆涓???????????瀛?绗?漿??負灏???褰㈠?锛?骞惰???杞??㈠????瀛?绗?覆锛?瀹??ユ?朵?涓?瀛?绗?覆绫誨???????般??

fn:toLowerCase?芥?扮??搴??ㄤ婦渚?锛?

l? fn:toLowerCase("Www.IT315.org")??杩????間負瀛?绗?覆??www.it315.org??

l? fn:toLowerCase("")??杩????間負绌哄??绗?覆

8.7.2? fn:toUpperCase?芥??/h3>

fn:toUpperCase?芥?闆?涓?涓?瀛?绗?覆涓???????????瀛?绗?漿??負澶у??褰㈠?锛?骞惰???杞??㈠????瀛?绗?覆锛?瀹??ユ?朵?涓?瀛?绗?覆绫誨???????般??

fn:toUpperCase?芥?扮??搴??ㄤ婦渚?锛?

l?fn:toUpperCase("Www.IT315.org") ??杩????間負瀛?绗?覆??WWW.IT315.ORG??

l?fn:toUpperCase("")??杩????間負绌哄??绗?覆

8.7.3? fn:trim?芥??/h3>

fn:trim?芥?闆???や?涓?瀛?绗?覆??棣?灏劇??绌烘?鹼?骞惰??????ょ┖?煎????缁???瀛?绗?覆锛?瀹??ユ?朵?涓?瀛?绗?覆绫誨???????般????瑕?娉ㄦ??????锛?fn:trim?芥?頒??藉???ゅ??绗?覆涓??翠?缃???绌烘?箋??

渚?濡?锛?fn:trim("?? www.it?315.org? ") ??杩????間負瀛?绗?覆??www.it? 315.org????

8.7.4? fn:escapeXml?芥??/h3>

fn:escapeXml?芥?闆?瀛?绗?覆涓?????瑕?杩?琛?杞?涔???HTML?規??瀛?绗???琛?.2杩?琛?HTML缂???杞????骞惰???杞??㈠????瀛?绗?覆锛?杩??峰氨??浠ュ?ㄦ?瑙??ㄤ腑?劇ず??TML?規??瀛?绗???fn:escapeXml?芥?版?ユ?朵?涓?瀛?绗?覆绫誨???????般??

渚?濡?锛?杩?琛?????濡?涓?浠g????JSP??浠跺??娴?瑙??ㄥ?璺寵漿?扳??http://www.it315.org??椤甸???杩?????涓鴻?浜?浠g??琚?娴?瑙??ㄤ?涓?TML??绛捐В???ц?锛?

<meta http-equiv="refresh" content="0;url=http://www.it315.org"/>

濡?????n:escapeXml?芥?闆???涓??㈢??浠g??锛?杩?琛?JSP??浠跺??灏卞?ㄦ?瑙??ㄧ???h??鴻?琛?浠g??锛?渚?绋?8-54??浣跨??n:escapeXml?芥?闆???涓??㈢??浠g????渚?瀛?绋?搴???

渚?绋?8-54? fn_escapeXml.jsp

?

<%@ taglibprefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

${fn:escapeXml('<metahttp-equiv="refresh"

????????????? content="0;url=http://www.it315.org"/>')}

?

fn_escapeXml.jsp椤甸?㈢??杩?琛?缁???濡???.46??绀恒??

??.46

8.7.5?fn:length?芥??/h3>

fn:length?芥?扮?ㄤ?杩???涓?涓????????扮?瀵矽薄涓?????????绱???涓??幫???杩???涓?涓?瀛?绗?覆涓???????瀛?绗???涓??幫?杩????間負int绫誨????fn:length?芥?版?ユ?朵?涓????幫?杩?涓????闆??浠ユ??<c:forEach>??绛劇??items灞??ф??????浠諱?绫誨??锛?????浠繪??绫誨?????扮???java.util.Collection??java.util.Iterator??java.util.Enumeration??java.util.Map绛?绫葷??瀹?渚?瀵矽薄??瀛?绗?覆??

濡???fn:length?芥?扮?????頒負null????????绱?涓??頒負0?????????扮?瀵矽薄锛????芥?拌???0锛?濡??????版??绌哄??绗?覆锛????芥?拌???0??渚?绋?8-55??浣跨??n:length?芥?扮??瀹?渚?绋?搴???

渚?绋?8-55? fn_length.jsp

?

<%@ taglibprefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>

<%@ pagecontentType="text/html;charset=gb2312" %>

<%@ pageimport="java.util.*, org.it315.UserBean" %>

<%

?????? Collection users = new ArrayList();

?????? for(int i=0; i<5; i++)

?????? {

????????????? UserBean user = new UserBean();

????????????? user.setUserName("user"+ i);

????????????? user.setPassword("guest"+ i);

????????????? users.add(user);

?????? }

?????? session.setAttribute("users",users);

%>

There are${fn:length(users)} users online.<hr />

瀛?绗?覆??www.it315.org??涓????? ${fn:length("www.it315.org")} 涓?瀛?绗?

?

fn_length.jsp椤甸?㈢??杩?琛?缁???濡???.47??绀恒??

??.47

8.7.6?fn:split?芥??/h3>

fn:split?芥?頒互??瀹?瀛?绗?覆浣?涓哄????绗??灏?涓?涓?瀛?绗?覆???叉??瀛?绗?覆?扮?骞惰???杩?涓?瀛?绗?覆?扮???fn:split?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?绗?涓?涓????拌〃绀鴻????茬??瀛?绗?覆锛?绗?浜?涓????拌〃绀轟?涓哄????绗???瀛?绗?覆??

l? fn:split?芥?闆????ava.util.StringTokenizer绫誨???插??绗?覆????浣?锛?寰??扮??瀛?绗?覆?扮?涓?????瀛?绗?覆??绱?涓?????????绗???韬?锛?渚?濡?锛?fn:split("www.it315.org",".")[1]??杩????間負瀛?绗?覆??it315????

l? 濡???绗?涓?涓????版??绌哄??绗?覆锛???fn:split?芥?拌?????瀛?绗?覆?扮?涓???????绌哄??绗?覆杩?涓?涓???绱?锛?渚?濡?锛?fn:split("",".")[0]??杩????間負绌哄??绗?覆??

l? 濡???绗?浜?涓????版??绌哄??绗?覆锛????芥?拌?????瀛?绗?覆?扮?涓???????婧?瀛?绗?覆杩?涓?涓???绱?锛?渚?濡?锛?fn:split("www.it315.org","")[0]??杩????間負瀛?绗?覆??www.it315.org??锛?fn:split("www.it315.org", "")[1]??杩????間負绌哄??绗?覆??

8.7.7? fn:join?芥??/h3>

fn:join?芥?頒互涓?涓?瀛?绗?覆浣?涓哄????绗??灏?涓?涓?瀛?绗?覆?扮?涓?????????绱???骞朵負涓?涓?瀛?绗?覆骞惰?????骞跺????缁???瀛?绗?覆??fn:join?芥?版?ユ?朵袱涓????幫?绗?涓?涓????版??瑕???浣???瀛?绗?覆?扮?锛?绗?浜?涓????版??浣?涓哄????绗???瀛?绗?覆??

濡???fn:join?芥?扮??绗?浜?涓????版??绌哄??绗?覆锛???fn:join?芥?扮??杩????兼??涓?浣跨?ㄤ換浣?????绗??瀛?绗?覆?扮?涓???????绱?杩??ヨ搗?ョ??缁???瀛?绗?覆??

fn:join?芥?扮??搴??ㄤ婦渚?锛?

l???璁?tringArray??淇?瀛???eb??涓???涓?涓?灞??э?瀹?琛ㄧず涓?涓??間負{"www","it315","org"}??瀛?绗?覆?扮?锛???fn:join(stringArray, ".")杩???瀛?绗?覆??www.it315.org??

l?fn:join(fn:split("www,it315,org",","), ".") ??杩????間負瀛?绗?覆??www.it315.org??

8.7.8? fn:indexOf?芥??/h3>

fn:indexOf?芥?拌?????瀹?瀛?绗?覆?ㄤ?涓?瀛?绗?覆涓?绗?涓?娆″?虹?扮??绱㈠??鹼?杩????間負int绫誨????fn:indexOf?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?濡???绗?涓?涓????闆??绗?覆涓?????绗?浜?涓????闆??绗?覆锛??d?锛?涓?绠$??浜?涓????闆??绗?覆?ㄧ??涓?涓????闆??绗?覆涓??虹?闆??娆★?fn:indexOf?芥?版?繪??杩???绗?涓?娆″?虹?扮??绱㈠??鹼?濡???绗?涓?涓????頒腑涓?????绗?浜?涓????幫???fn:indexOf?芥?拌???-1??濡???绗?浜?涓????頒負绌哄??绗?覆锛???fn:indexOf?芥?版?繪??杩???0??

fn:indexOf?芥?扮??搴??ㄤ婦渚?锛?

l?fn:indexOf("www.it315.org","t3")??杩????間負5

l?fn:indexOf("www.it315.org","aaa")??杩????間負 -1

l?fn:indexOf("www.it315.org","")??杩????間負0

8.7.9? fn:contains?芥??/h3>

fn:contains?芥?版?娴?涓?涓?瀛?绗?覆涓???????????瀹???瀛?绗?覆锛?杩????間負甯?灏?绫誨????fn:contains?芥?闆?ㄦ??杈?涓や釜瀛?绗?覆?????哥???舵??澶у???????????

fn:contains?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?濡???绗?涓?涓????闆??绗?覆涓?????绗?浜?涓????闆??绗?覆锛???fn:contains?芥?拌???true锛?????杩???false??濡???绗?浜?涓????扮???間負绌哄??绗?覆锛???fn:contains?芥?版?繪??杩???true??瀹???涓?锛?fn:contains(string, substring)绛?浠蜂?fn:indexOf(string, substring) != -1??

fn:contains?芥?扮??搴??ㄤ婦渚?锛?

l?fn:contains("www.it315.org", "org")??杩????間負true

l?fn:contains("www.it315.org","Org")??杩????間負false

l?fn:contains("", "")??杩????間負true

8.7.10? fn:containsIgnoreCase?芥??/h3>

fn:containsIgnoreCase?芥?版?娴?涓?涓?瀛?绗?覆涓???????????瀹???瀛?绗?覆锛??ㄦ??杈?涓や釜瀛?绗?覆?????哥???跺ぇ灏???涓???????fn:containsIgnoreCase?芥?扮?????闆??杩????肩??绫誨???戒?fn:contains?芥?扮?稿??锛??????????ㄦ??杈?涓や釜瀛?绗?覆?????哥???朵?????瀛?绗???澶у???锛???????????瀛?绗???澶у???锛?fn:containsIgnoreCase(string,substring)绛?浠蜂?fn:contains(fn:toUpperCase(string),fn:toUpperCase(substring))??

fn:containsIgnoreCase?芥?扮??搴??ㄤ婦渚?锛?

l?fn:containsIgnoreCase("www.it315.org","Org") ??杩????間負 true

l?fn:containsIgnoreCase (fn:toUpperCase("www.it315.org"),fn:toUpperCase("Org"))??杩????間負true

8.7.11?fn:startsWith?芥??/h3>

fn:startsWith?芥?扮?ㄤ?妫?娴?涓?涓?瀛?绗?覆??????浠ユ??瀹?瀛?绗?覆寮?濮???锛?杩????間負甯?灏?绫誨????

fn:startsWith?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?濡???绗?涓?涓????闆??绗?覆浠ョ??浜?涓????闆??绗?覆寮?濮?锛????芥?拌???true锛??????芥?拌???false??濡???绗?浜?涓????頒負绌哄??绗?覆锛???fn:startsWith?芥?版?繪??杩???true??瀹???涓?锛?fn:startsWith(string, prefix)绛?浠蜂?琛ㄨ揪寮?fn:indexOf(string, prefix) == 0??

fn:startsWith?芥?扮??搴??ㄤ婦渚?锛?

l?fn:startsWith("www.it315.org","it315")??杩????間負false

l?fn:startsWith("www.it315.org","www")??杩????間負true

l?fn:startsWith("www.it315.org","")??杩????間負true

8.7.12?fn:endsWith?芥??/h3>

fn:endsWith?芥?扮?ㄤ?妫?娴?涓?涓?瀛?绗?覆??????浠ユ??瀹?瀛?绗?覆缁?????锛?杩????間負甯?灏?绫誨????

fn:endsWith?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?濡???绗?涓?涓????闆??绗?覆浠ョ??浜?涓????闆??绗?覆缁???锛????芥?拌???true锛??????芥?拌???false??濡???绗?浜?涓????頒負绌哄??绗?覆锛???fn:endsWith?芥?版?繪??杩???true??

fn:endsWith?芥?扮??搴??ㄤ婦渚?锛?

l?fn:endsWith("www.it315.org","it315")??杩????間負false

l?fn:endsWith("www.it315.org","org")??杩????間負true

l?fn:endsWith("www.it315.org","")??杩????間負true

8.7.13? fn:replace?芥??/h3>

fn:replace?芥?闆?涓?涓?瀛?绗?覆涓?????????瀹?瀛?瀛?绗?覆?挎??負?跺??????瀹?瀛?绗?覆锛?骞惰????挎?㈠????缁???瀛?绗?覆??fn:replace?規??ユ?朵?涓?瀛?绗?覆绫誨???????幫?绗?涓?涓????拌〃绀鴻???浣???婧?瀛?绗?覆锛?绗?浜?涓????拌〃绀烘?瀛?绗?覆涓?瑕?琚??挎?㈢??瀛?瀛?绗?覆锛?绗?涓?涓????拌〃绀鴻?琚??挎?㈡????瀛?绗?覆??

fn:replace?芥?版???т??㈢??璇存???ц?瀛?绗?覆???挎?㈡??浣?锛?

锛?1锛?婧?瀛?绗?覆涓???????绗?浜?涓????版??瀹???瀛?瀛?绗?覆?借??挎?㈡??绗?涓?涓????版??瀹???瀛?绗?覆锛?濡????挎?㈠????缁???瀛?绗?覆涓?????绗?浜?涓????版??瀹???瀛?瀛?绗?覆锛???涓???杩?琛??挎????渚?濡?锛?

l? fn:replace("www it315 org", " ",".")??杩????間負瀛?绗?覆??www.it315.org??

l? fn:replace("ddabccff", "abc","ab")??杩????間負瀛?绗?覆??ddabcff??锛?杩?涓?瀛?绗?覆涓?杩?????瀛?绗?覆??abc??锛?浣?涓????ц??挎?㈡??浣?

锛?2锛?濡???绗?涓?涓????版??绌哄??绗?覆锛???fn:replace?芥?拌???绌哄??绗?覆锛?渚?濡?锛?fn:replace("", " ", ".")??杩????間負绌哄??绗?覆??

锛?3锛?濡???绗?浜?涓????版??绌哄??绗?覆锛???fn:replace?芥?頒??ц?浠諱??挎?㈡??浣?锛?杩???绗?涓?涓????版??瀹???瀛?绗?覆??渚?濡?锛?fn:replace("www.it315.org","", " ") ??杩????間負瀛?绗?覆??www.it315.org????

锛?4锛?濡???绗?涓?涓????版??绌哄??绗?覆锛???fn:replace?芥?闆???ゆ?瀛?绗?覆涓???????绗?浜?涓????版??瀹???瀛?瀛?绗?覆??渚?濡?锛?fn:replace("www.it315.org",".", "")??杩????間負瀛?绗?覆??wwwit315org????

8.7.14? fn:substring?芥??/h3>

fn:substring?芥?扮?ㄤ?????涓?涓?瀛?绗?覆??瀛?瀛?绗?覆骞惰????????扮??瀛?瀛?绗?覆??fn:substring?芥?版?ユ?朵?涓????幫?绗?涓?涓????版???ㄤ???瀹?瑕???浣???婧?瀛?绗?覆锛?绗?浜?涓????版???ㄤ???瀹?????瀛?瀛?绗?覆寮?濮???绱㈠??鹼?绗?涓?涓????版???ㄤ???瀹?????瀛?瀛?绗?覆缁?????绱㈠??鹼?绗?浜?涓????闆??绗?涓?涓????伴?芥??int绫誨??锛??跺?奸?戒?0寮?濮???

fn:substring?芥?版???т??㈢??璇存??????涓?涓?瀛?绗?覆??瀛?瀛?绗?覆锛?

l? 濡???绗?浜?涓????扮???煎ぇ浜???绛?浜?婧?瀛?绗?覆涓???????瀛?绗?釜?幫???fn:substring?芥?拌???绌哄??绗?覆锛?

l? 濡???绗?浜?涓????扮???煎?浜?0锛???灏??跺?艱?劇疆涓?锛?

l? 濡???绗?涓?涓????扮???煎?浜?0??澶т?婧?瀛?绗?覆涓???????瀛?绗?釜?幫????????版?瀛?绗?覆??缁?灏劇??瀛?绗??

l? 濡???绗?涓?涓????扮???煎?浜?绗?浜?涓????扮???鹼???fn:substring?芥?拌???绌哄??绗?覆??

fn:substring?芥?扮??搴??ㄤ婦渚?锛?瀛?绗?覆??www.it315.org??涓?????13涓?瀛?绗??锛?

l?fn:substring("www.it315.org", 4, 9) ??杩????間負瀛?绗?覆??it315??

l?fn:substring("www.it315.org", 13, 14)杩???绌哄??绗?覆

l?fn:substring("www.it315.org", -1, 9) ??杩????間負瀛?绗?覆??www.it315??

l?fn:substring("www.it315.org", 4, -1) ??杩????間負瀛?绗?覆??it315.org??

l?fn:substring("www.it315.org", 4, 13) ??杩????間負瀛?绗?覆??it315.org??

l?fn:substring("www.it315.org", 4, 3) 杩???绌哄??绗?覆

8.7.15? fn:substringAfter?芥??/h3>

fn:substringAfter?芥?扮?ㄤ?????骞惰???涓?涓?瀛?绗?覆涓?????瀹?瀛?瀛?绗?覆绗?涓?娆″?虹?頒?????瀛?瀛?绗?覆??fn:substringAfter?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?绗?涓?涓????拌〃绀鴻???浣???婧?瀛?绗?覆锛?绗?浜?涓????拌〃绀烘??瀹???瀛?瀛?绗?覆锛?渚?濡?锛?fn:substringAfter("www.it315.org",".")??杩????間負瀛?绗?覆??it315.org????

fn:substringAfter?芥?版???т??㈢??璇存??????涓?涓?瀛?绗?覆??瀛?瀛?绗?覆锛?

l? 濡???绗?涓?涓????版??绌哄??绗?覆锛???fn:substringAfter?芥?拌???绌哄??绗?覆锛?渚?濡?fn:substringAfter("",".") ??杩????間負绌哄??绗?覆锛?

l? 濡???绗?浜?涓????版??绌哄??绗?覆锛???fn:substringAfter?芥?扮??杩????間負婧?瀛?绗?覆锛?渚?濡?锛?fn:substringAfter("www.it315.org","")??杩????間負瀛?绗?覆??www.it315.org??锛?

l?濡???绗?浜?涓????頒???绗?涓?涓????扮??瀛?瀛?绗?覆锛???substringAfter?芥?拌???绌哄??绗?覆锛?渚?濡?锛?fn:substringAfter("www.it315.org","itorg")??杩????間負绌哄??绗?覆??

8.7.16? fn:substringBefore?芥??/h3>

fn:substringBefore?芥?扮?ㄤ?????骞惰???涓?涓?瀛?绗?覆涓?????瀹?瀛?瀛?绗?覆绗?涓?娆″?虹?頒?????瀛?瀛?绗?覆??fn:substringBefore?芥?版?ユ?朵袱涓?瀛?绗?覆绫誨???????幫?绗?涓?涓????拌〃绀鴻???浣???婧?瀛?绗?覆锛?绗?浜?涓????拌〃绀烘??瀹???瀛?瀛?绗?覆锛?渚?濡?锛?fn:substringBefore("www.it315.org",".") ??杩????間負瀛?绗?覆??www????

fn:substringBefore?芥?版???т??㈢??璇存??????涓?涓?瀛?绗?覆??瀛?瀛?绗?覆锛?

l? 濡???绗?涓?涓????版??绌哄??绗?覆锛???fn:substringBefore?芥?拌???绌哄??绗?覆锛?渚?濡?锛?fn:substringBefore("",".") ??杩????間負绌哄??绗?覆锛?

l? 濡???绗?浜?涓????版??绌哄??绗?覆锛???fn:substringBefore?芥?拌???绌哄??绗?覆锛?渚?濡?锛?fn:substringBefore("www.it315.org","") ??杩????間負绌哄??绗?覆

l?濡???绗?浜?涓????頒???绗?涓?涓????扮??瀛?瀛?绗?覆锛???fn:substringBefore?芥?拌???绌哄??绗?覆锛?渚?濡?锛?fn:substringBefore("www.it315.org","itorg") ??杩????間負绌哄??绗?覆??

?

?

????棰?锛?

?

1??璇風??lt;c:forEach>??绛懼?ㄤ?涓?table琛ㄦ?間腑??琛ㄦ?劇ず?轟?涓?????瀵矽薄涓?????????绱?锛?濂??惰??ㄦ?????擱?寸??棰??茶?琛???????

?

2??璇風??lt;c:forEach>??绛懼?涓?涓??存?版?扮?涓???????绱??ㄩ???峰????????1,2,3????褰㈠?杩?琛?杈??猴?娉ㄦ??锛?????涓?涓???绱????㈡病?????楓??

?

3??璇峰?濂?璋???lt;c:forTokens>??绛炬???闆??ttp://www.it315.org/deal.jsp?name=zxx&password=123涓???姣?涓????闆???????闆?箋??

?

4?? 璇峰??L琛ㄨ揪寮???STL?芥??n:split??fn:length???哄??绗?覆"a/b/c/d.txt"涓???????涓?涓?"/"???㈢????瀹廣??

?