天天看点

张孝祥老师编写的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"涓???????涓?涓?"/"???㈢????瀹广??

?