Tomcat 與 JavaWeb 開發技術詳解, 3/e
內容描述
本書結合最新的Tomcat 9版本,詳細介紹了開發Java Web應用的各種技術。主要內容包括:Tomcat和Java Web開發的基礎知識,Java Web開發的高級技術,在Java Web應用中運用第三方提供的實用軟件(如Spring、Velocity和Log4J)的方法,以及Tomcat的各種高級功能。書中內容註重理論與實踐相結合,列舉了大量具有典型性和實用價值的Web應用實例,並提供了詳細的開發和部署步驟。由於Java Web技術是Oracle公司在Java Servlet規範中提出的通用技術,因此本書講解的Java Web應用例子可以運行在任何一個實現Oracle的Servlet規範的Java Web服務器上。隨書附贈光盤內容為本書所有範例源程序,視頻教程,以及本書涉及的部分軟件的最新版本的安裝程序。本書語言深入淺出,通俗易懂。無論對於Java Web開發的新手還是行家來說,本書都是精通Tomcat和開發Java Web應用的必備的實用手冊。本書還可作為高校的學習Java Web開發的教材,以及企業Java Web培訓教材。
目錄大綱
第1篇
Java Web開發技術詳解
第1章Web運作原理探析.......................1
1.1 Web的概念....... ......................................2
1.2 HTML簡介........ .....................................3
1.3 URL簡介......... .......................................5
1.4 HTTP簡介....... .......................................6
1.4.1 HTTP請求格式.... ......................8
1.4.2 HTTP響應的格式.................... 10
1.4.3正文部分的MIME類型...........12
1.4.4 HTTP各個版本的特點.............12
1.5用Java套接字創建HTTP客戶與服務器
程序............................................. ..........14
1.5.1演示異構系統之間用HTTP協議
通信.......................... ....................18
1.5.2演示對網頁中超鏈接的處理過程
.................................................. ....21
1.5.3演示對網頁中圖片的處理過程22
1.6 Web的發展歷程............................ .......22
1.6.1發布靜態HTML文檔..............23
1.6.2發布靜態多媒體信息................23
1.6.3提供瀏覽器端與用戶的動態交互
功能............. .................................24
1.6.4提供服務器端與用戶的動態交互
功能.... ..........................................25
1.6.5發布Web應用. .........................30
1.6.6發布Web服務.................. ........31
1.6.7 Web2.0:全民共建的Web.......34
1.6.8 Web3.0:智能化處理海量信息35
1.7處理HTTP請求參數以及HTML表單35
1.8客戶端向服務器端上傳文件................38
1.9小結...................... .................................44
1.10思考題............. ....................................44
第2章Tomcat簡介........ ........................49
2.1 Tomcat概述...................... .....................50
2.2 Tomcat作為Servlet容器的基本功能..51
2.3 Tomcat的組成結構...............................52
2.4 Tomcat的工作模式...............................55
2.5 Tomcat的版本........... ............................57
2.6安裝和配置Tomcat所需的資源..........59
2.7安裝Tomcat...........................................60
2.8啟動Tomcat並測試Tomcat的安裝....61
2.9 Tomcat的運行腳本...............................63
2.10小結.. .................................................. .64
2.11思考題............................................. ....64
第3章第一個JavaWeb應用.................67
3.1 JavaWeb應用簡介............... .................67
3.2創建JavaWeb應用............................ ...68
3.2.1 JavaWeb應用的目錄結構........68
3.2.2創建HTML文件......................70
3.2.3創建Servlet類............... ...........70
3.2.4創建JSP文件...........................72
3.2.5創建web.xml文件....................72
3.3在Tomcat中發布JavaWeb應用74
3.3.1 Tomcat的目錄結構.......... ........74
3.3.2按照默認方式發布JavaWeb應用
................................ .....................75
3.3.3 Web組件的URL..................... .76
3.3.4配置Tomcat的<Context>元素.80
3.3.5配置Tomcat的虛擬主機..........82
3.4創建、配置和使用自定義JSP標籤....85
3.5用批處理文件或ANT編譯範例..........89
3.6小結.............................. .........................90
3.7思考題..................... ..............................91
第4章Servlet技術(上).....................93
4.1 Servlet API................. ............................94
4.1.1 Servlet接口................ ...............95
4.1.2 GenericServlet抽像類...............96
4.1.3 HttpServlet抽像類...... ..............98
4.1.4 ServletRequest接口................101
4.1.5 HttpServletRequest接口........ .102
4.1.6 ServletResponse接口..............104
4.1.7 HttpServletResponse接口.......106
4.1.8 ServletConfig接口.......... ........108
4.1.9 ServletContext接口................110
4.2 JavaWeb應用的生命週期............. ..... 113
4.2.1啟動階段.................................113
4.2.2運行時階段.............................113
4.2.3終止階段.................................114
4.2.4用Tomcat的管理平台管理Web
應用的生命週期........................114
4.3 Servlet的生命週期................. ............ 116
4.3.1初始化階段.............................116
4.3. 2運行時階段.............................117
4.3.3銷毀階段........... ......................117
4.3.4演示Servlet的生命週期的範例
................. ...................................118
4.4 ServletContext與Web應用範圍........ 121
4.4.1在Web應用範圍內存放共享數據
的範例.................................... ....122
4.4.2使用ServletContextListener監聽
器...................................... ..........124
4.5 Servlet的服務方法拋出異常..............127
4.6防止頁面被客戶端緩存......................128
4.7使用Annotation標註配置Servlet......129
4.8處理HTTP請求參數中的中文字符編碼
............................................... ..............131
4.9小結................................. ....................133
4.10思考題.......................... .....................135
第5章Servlet技術(下).................... .139
5.1下載文件............................................. 139
5.2上傳文件.............................................141
5.2.1利用Apache開源類庫實現文件上
傳...................................... ..........142
5.2.2利用Servlet API中的Part接口實
現文件上傳......................... .......146
5.3動態生成圖像.....................................149
5.4讀寫Cookie.........................................152
5.5訪問Web應用的工作目錄.................159
5.6轉發和包含......................... ................161
5.6.1請求轉發............................ .....162
5.6.2包含........................................ .166
5.6.3請求範圍.................................168
5.7重定向...... ...........................................168
5.8訪問Servlet容器內的其他Web應用172
5.9避免並發問題.....................................173
5.9.1合理決定在Servlet中定義的變量
的作用域類型............................176
5.9.2使用Java同步機制對多線程同步
................................................. ..178
5.9.3被廢棄的SingleThreadModel接口
.................................................. .179
5.10對客戶請求的異步處理....................181
5.10.1異步處理的流程............. ......181
5.10.2異步處理的範例...................182
5.10.3異步監聽器.......... .................186
5.10.4非阻塞I/O........................ .....187
5.11服務器端推送....................................191
5.12小結. .................................................. 193
5.13思考題.............................................. .196
第6章JSP技術....................................199
6.1比較HTML、Servlet和JSP..............199
6.1.1靜態HTML文件....................199
6.1.2用Servlet動態生成HTML頁面
................................................ ....200
6.1.3用JSP動態生成HTML頁面201
6.2 JSP語法..................................... .........205
6.2.1 JSP指令(Directive)............206
6.2.2 JSP聲明.............. ....................208
6.2.3 Java程序片段(Scriptlet)....209
6.2.4 Java表達式......... ....................210
6.2.5隱含對象....................... ..........212
6.3 JSP的生命週期.................................. .214
6.4請求轉發............................................. 216
6.5包含............................................... ......218
6.5.1靜態包含.................................218
6.5.2動態包含.................................220
6.5.3混合使用靜態包含和動態包含
..... ...............................................222
6.6 JSP異常處理.......................................229
6.7再談發布JSP. ......................................232
6.8預編譯JSP ....... ...................................232
6.9 PageContext類的用法......... ...............234
6.10在web.xml中配置JSP.....................236
6.11 JSP技術的發展趨勢.........................237
6.12小結.................... ...............................238
6.13思考題............... ................................238
第7章bookstore應用簡介........... .......243
7.1 bookstore應用的軟件結構.................243
7.1.1 Web服務器層............ .............244
7.1.2數據庫層............................... ..244
7.2瀏覽bookstore應用的JSP網頁........244
7.3 JavaBean和實用類.............................248
7.3.1實體類.......... ...........................248
7.3.2購物車的實現............... ..........249
7.4發布bookstore應用............................252
7.5小結.... .................................................253
第8章訪問數據庫...............................255
8.1安裝和配置MySQL數據庫....... ........255
8.2 JDBC簡介...................................... .....257
8.2.1 java.sql包中的接口和類........260
8.2.2編寫訪問數據庫程序的步驟..263
8.2.3事務處理...... ...........................266
8.3通過JDBC API訪問數據庫的JSP範例程
序........... ..............................................267
8.4 bookstore應用通過JDBC API訪問數據
庫................................................. ........269
8.5數據源(DataSource)簡介...............274
8.6配置數據源.............. ...........................276
8.6.1在context.xml中加入<Resource>
元素......... ...................................276
8.6.2在web.xml中加入<resource-ref>
元素............................................277
8.7程序中訪問數據源..............................277
8.7.1通過數據源連接數據庫的JSP範
例程序.... ....................................278
8.7.2 bookstore應用通過數據源連接數
據庫. ...........................................279
8.8處理數據庫中數據的中文字符編碼..282
8.9分頁顯示批量數據..............................283
8.10用可滾動結果集分頁顯示批量數據287
8.11小結................................................ ...290
8.11思考題........................................... ....291
第9章HTTP會話的使用與管理........295
9.1會話簡介........................ .....................295
9.2 HttpSession的生命週期及會話範圍..299
9.3使用會話的JSP範例程序.......... ........301
9.4使用會話的Servlet範例程序............305
9.5通過重寫URL來跟踪會話............. ...308
9.6會話的持久化......................................312
9.6. 1標準會話管理器StandardManager
............................................ ........315
9.6.2持久化會話管理器
PersistentManager ......................315
9.7會話的監聽..... ....................................320
9.7.1用HttpSessionListener統計在線
用戶人數....................................324
9.7.2用HttpSessionBindingListener統
計在線用戶人數. .......................326
9.8小結........................ .............................330
9.9思考題................. ................................331
第10章JSP訪問JavaBean........... .......335
10.1 JavaBean簡介...................................335
10.2 JSP訪問JavaBean的語法...............336
10.3 JavaBean的範圍........................... ....338
10.3.1 JavaBean在頁面(page)範圍內
.................................. ..................339
10.3.2 JavaBean在請求(request)範圍
內.................... ............................341
10.3.3 JavaBean在會話(session)範圍
內................................................343
10.3.4 JavaBean在Web應用
(application)範圍內..............344
10.4在bookstore應用中訪問JavaBean..345
10.4.1訪問BookDB類....... ............345
10.4.2訪問ShoppingCart類...........346
10.5小結................. ..................................350
10.6思考題............ ...................................351
第11章開發JavaMail Web應用....... ..355
11.1 E-mail協議簡介................................355
11.1.1 SMTP簡單郵件傳輸協議....356
11.1.2 POP3郵局協議.....................356
11.1.3接收郵件的新協議IMAP.....356
11.2 JavaMail API簡介.............................357
11.3建立JavaMail應用程序的開發環境359
11.3.1獲得JavaMail API的類庫....360
11.3.2安裝和配置郵件服務器........360
11.4創建JavaMail應用程序.............. .....362
11.5 JavaMail Web應用簡介....................366
11.6 JavaMail Web應用的程序結構........367
11.6. 1重新封裝Message數據........368
11.6.2用於保存郵件賬號信息的
JavaBean ......................... ...........371
11.6.3定義所有JSP文件的相同內容
............................ .......................373
11.6.4登錄IMAP服務器上的郵件賬號
................ ...................................375
11.6.5管理郵件夾........ ...................377
11.6.6查看郵件夾中的郵件信息....380
11.6.7查看郵件內容......... ..............384
11.6.8創建和發送郵件....................385
11.6.9退出郵件系統.......................388
11.7在Tomcat中配置郵件會話(Mail
Session)......... ....................................388
11.7.1在context.xml中配置Mail
Session資源. ..............................388
11.7.2在web.xml中加入對JNDI Mail
Session資源的引用... ................389
11.7.3在javamail應用中獲取JNDI
Mail Session資源..................... .389
11.8發布和運行javamail應用................391
11.9小結....................... ............................392
11.10思考題.................. ............................392
第12章EL表達式語言.............. .........395
12.1基本語法..................................... ......395
12.1.1訪問對象的屬性及數組的元素
.................................................. .396
12.1.2 EL運算符.............................396
12.1.3隱含對象...... .........................398
12.1.4命名變量................... ............399
12.2使用EL表達式的JSP範例.............400
12.2.1關於基本語法的例子....... .....400
12.2.2讀取HTML表單數據的例子402
12.2.3訪問命名變量的例子............403
12.3定義和使用EL函數...... ...................403
12.4小結............................ .......................406
12.5思考題....................... ........................407
第13章自定義JSP標籤.................. ...409
13.1自定義JSP標籤簡介........................409
13.2 JSP Tag API........... .............................410
13.2.1 JspTag接口...........................411
13.2.2 Tag接口............ ....................411
13.2.3 IterationTag接口...................413
13.2.4 BodyTag接口........................414
13.2.5 TagSupport類和BodyTagSupport
類................ ................................416
13.3 message標籤範例(訪問標籤屬性)
........ .................................................. ...420
13.3.1創建message標籤的處理類
MessageTag................................421
13.3.2創建標籤庫描述文件............425
13.3.3在Web應用中使用標籤......427
13.3.4發布支持中、英文版本的
helloapp應用.... .........................429
13.4 iterate標籤範例(重複執行標籤主體)
.................................................. ...........431
13.5 greet標籤範例(訪問標籤主體內容)
............................ .................................435
13.6小結.............. .....................................439
13.7思考題......... ......................................440
第14章採用模板設計網上書店應用443
14.1如何設計網站的模板........................443
14.2創建負責流程控制的Servlet............444
14.3創建模板標籤和模板JSP文件........446
14.3.1 <parameter>標籤和其處理類448
14.3.2 <screen>標籤和處理類.........451
14.3 .3 <definition>標籤和處理類....453
14.3.4 <insert>標籤和處理類..........457
14.4修改JSP文件........... .........................459
14.5發布採用模板設計的bookstore應用
.................................................. ...........460
14.6小結.................................... ...............463
第15章JSTL Core標籤庫...................465
15.1使用第三方提供的標籤庫的步驟....465
15.2 JSTL標籤庫簡介..............................466
15.3一般用途的標籤. ...............................467
15.3.1 <c:out>標籤......... ..................468
15.3.2 <c:set>標籤...................... .....469
15.3.3 <c:remove>標籤....................470
15.3.4 <c:catch>標籤..... ...................471
15.4條件標籤........................... ................471
15.4.1 <c:if>標籤........................ .....471
15.4.2 <c:choose> 、<c:when>和
<c:otherwise>標籤.....................472
15.5迭代標籤...........................................473
15.5.1 <c:forEach>標籤...................473
15.5.2 <c:forTokens>標籤............... .477
15.6 URL相關的標籤...............................478
15.6.1 <c:import>標籤.. ...................478
15.6.2 <c:url>標籤..................... ......479
15.6.3 <c:redirect>標籤....................480
15.7小結........... ........................................481
15.8思考題...... .........................................481
第16章JSTL I18N標籤庫. .................485
16.1國際化的概念........................... .........485
16.2 Java語言對I18N的支持.................486
16.2.1 Locale類.......... .....................486
16.2.2 ResourceBundle類................490
16.2.3 MessageFormat類和復合消息
.................... ................................492
16.3國際化標籤............. ...........................494
16.3.1 <fmt:setLocale>標籤............. 494
16.3.2 <fmt:setBundle>標籤............495
16.3.3 <fmt:bundle>標籤.................496
16.3.4 <fmt:message>標籤...............496
16.3.5 <fmt:param>標籤................ ..497
16.3.6 <fmt:requestEncoding>標籤..498
16.4創建國際化的Web應用...................498
16.4.1創建支持國際化的網頁........499
16.4.2創建資源文件.......................502
16.5格式化標籤...... ..................................503
16.5.1 <fmt:setTimeZone>標籤...... .503
16.5.2 <fmt:timeZone>標籤.............503
16.5.3 <fmt:formatNumber>標籤.....504
16.5.4 <fmt:parseNumber>標籤... ....505
16.5.5 <fmt:formatDate>標籤..........506
16.5.6 <fmt:parseDate>標籤............507
16.6小結. .................................................. 508
16.7思考題.............................................. .509
第17章JSTL Sql標籤庫.....................513
17.1 <sql:setDataSource>標籤............ ......513
17.2 <sql:query>標籤................................514
17.2.1設置數據源...........................514
17.2.2設置select查詢語句............ 515
17.2.3控制實際取出的記錄............515
17.2.4訪問查詢結果...................... .515
17.2.5使用<sql:query>標籤的範例516
17.3 <sql:param>標籤...............................519
17.4 <sql:dateParam>標籤.... .....................519
17.5 <sql:update>標籤..................... ..........520
17.6 <sql:transaction>標籤........................521
17.7小結..... ..............................................522
17.8思考題...............................................523
第18章JSTL Functions標籤庫...........525
18.1 fn:contains函數............................ .....525
18.2 fn:containsIgnoreCase函數...............525
18.3 fn:startsWith函數.................. ............526
18.4 fn:endsWith函數...............................526
18.5 fn:indexOf函數.................................526
18.6 fn:replace函數...................................527
18.7 fn:substring函數.... ...........................527
18.8 fn:substringBefore函數................. ....528
18.9 fn:substringAfter函數.......................528
18.10 fn:split函數........... ..........................528
18.11 fn:join函數.................. ....................529
18.12 fn:toLowerCase函數.......................529
18.13 fn:toUpperCase函數.......................530
18.14 fn:trim函數................ .....................530
18.15 fn:escapeXml函數....................... ...530
18.16 fn:length函數..................................531
18.17小結.... .............................................532
18.18思考題.............................................533
第19章簡單標籤和標籤文件.............535
19.1實現SimpleTag接口........................535
19.1.1創建和使用<hello>簡單標籤537
19.1.2創建和使用帶屬性和標籤主體
的<welcome>簡單標籤.............538
19.1.3創建和使用帶動態屬性的
<max>簡單標籤........................540
19.2使用標籤文件............. .......................541
19.2.1標籤文件的隱含對象...........545
19.2.2標籤文件的指令...................546
19.2.3標籤文件的<jsp:invoke>和
<jsp:doBody>動作元素......... ....547
19.2.4創建和使用帶屬性和標籤主體
的display標籤文件..................548
19.2.5創建和使用帶屬性和標籤主體
的welcome標籤文件................549
19.2.6創建和使用帶變量的precode標
簽文件........................................551
19.3小結..... ..............................................552
19.4思考題...............................................552
第20章過濾器.....................................555
20.1過濾器簡介..... ...................................555
20.2創建過濾器.......... ..............................556
20.3發布過濾器............... .........................560
20.3.1在web.xml文件中配置過濾器
............ ........................................560
20.3.2用@WebFilter標註來配置過濾
器................................................ 561
20.3.3用NoteFilter來過濾NoteServlet
的範例....................................... .562
20.4串聯過濾器........................................566
20.4.1包裝設計模式簡介...............567
20.4.2 ServletOutputStream的包裝類
......................... ...........................569
20.4.3 HttpServletResponse的包裝類
............... .....................................572
20.4.4創建對響應結果進行字符串替
換的過濾器................................573
20.4.5 ReplaceTextFilter過濾器工作的
UML時序圖... ...........................574
20.4.6發布和運行包含
ReplaceTextFilter過濾器的Web應
用........ ........................................576
20.5異步處理過濾器.... ............................579
20.6小結................... ................................582
20.7思考題............................................... 582
第21章Web應用中訪問EJB組件....587
21.1 JavaEE體系結構簡介.......................587
21.2安裝和配置WildFly服務器.............589
21.3創建EJB組件................................ ...590
21.3.1編寫Remote接口.................591
21.3.2編寫Enterprise Java Bean類591
21.4在Web應用中訪問EJB組件..... .....593
21.5發布JavaEE應用..............................595
21.5.1在WildFly上發布EJB組件595
21.5.2在WildFly上發布Web應用596
21.5.3在WildFly上發布JavaEE應用
.............................. .....................597
21.6小結.......................... .........................598
21.7思考題..................... ..........................600
第22章Web應用中訪問Web服務....601
22.1 SOAP簡介................................. .......601
22.2在Tomcat上發布Axis Web應用....603
22.3創建SOAP服務......................... ......604
22.3.1創建提供SOAP服務的Java類
................................. ..................605
22.3.2創建SOAP服務的發布描述文件
..................... ..............................605
22.4發布和管理SOAP服務............. ......606
22.4.1發布SOAP服務...................606
22.4.2管理SOAP服務........... ........607
22.5創建和運行SOAP客戶程序............609
22.6在bookstore應用中訪問SOAP服務
............. ................................................ 611
22.6 .1對SOAP服務方法的參數和返回
值的限制....................................611
22.6.2創建BookDB服務類及
BookDBDelegate代理類...........612
22.6.3發布BookDBService服務和
bookstore應用...........................617
22.7小結................................................ ...619
22.8思考題........................................... ....620
第23章Web應用的MVC設計模式623
23.1 MVC設計模式簡介..........................623
23.2 JSP Model1和JSP Model2...............625
23.3 Spring MVC概述........................... ...627
23.3.1 Spring MVC的框架結構......627
23.3.2 Spring MVC的工作流程......630
23.4創建採用Spring MVC的Web應用630
23.4.1建立Spring MVC的環境.....630
23.4.2創建視圖...............................631
23.4.3創建模型...............................632
23.4.4創建Controller組件....... ......633
23.4.5創建web.xml文件和Spring
MVC配置文件.........................636
23.5運行helloapp應用............................637
23.6小結................... ................................638
23.7思考題.............. .................................638
第2篇
Tomcat配置及第三方實用軟件的用法
第24章Tomcat的管理平台................641
24.1訪問Tomcat的管理平台..................641
24.2 Tomcat的管理平台...........................642
24.2.1管理Web應用................ ......642
24.2.2管理HTTP會話...................644
24.2.3查看Tomcat服務器信息......645
24.3小結................................................ ...646
第25章安全域.....................................647
25.1安全域概述........................................647
25.2為Web資源設置安全約束. ..............648
25.2.1在web.xml中加入
<security-constraint>元素..........649
25.2.2在web.xml中加入<login-config>
元素............................................ 651
25.2.3在web.xml中加入
<security-role>元素...................654
25.3內存域........... ....................................655
25.4 JDBC域.......... ...................................656
25.4.1用戶數據庫的結構....... ........656
25.4.2在MySQL中創建和配置用戶數
據庫............................ ................657
25.4.3配置<Realm>元素.................658
25.5 DataSource域..................... ...............659
25.6在Web應用中訪問用戶信息...........660
25.7小結............ .......................................661
25.8思考題....... ........................................661
第26章Tomcat與其他HTTP服務器集成
.................................................. .................663
26.1 Tomcat與HTTP服務器集成的原理663
26.1.1 JK插件.................. ................664
26.1.2 AJP協議............................ ....665
26.2在Windows下Tomcat與Apache服務器
集成.................................... .................665
26.3在Linux下Tomcat與Apache服務器集
成...................... ...................................668
26.4 Tomcat與IIS服務器集成................670
26.4.1安裝和啟動IIS服務器.........670
26.4.2準備相關文件... ....................671
26.4.3編輯註冊表....................... ....672
26.4.4在IIS中加入“jakarta”虛擬目
錄................................ ................673
26.4.5把JK插件作為ISAPI篩選器加
入到IIS................... ...................674
26.4.6測試配置......................... ......675
26.5 Tomcat集群.......................................675
26.5.1配置集群系統的負載平衡器676
26.5.2配置集群管理器...................678
26.6小結.......... .........................................682
26.7思考題..... ..........................................683
第27章在Tomcat中配置SSI.............685
27.1 SSI簡介.............................................685
27.1 .1 #echo指令.............................686
27.1.2 #include指令......... ................688
27.1.3 #flastmod指令......................689
27.1.4 # fsize指令.............................690
27.1.5 #exec指令............ .................690
27.1.6 #config指令.......................... 690
27.1.7 #if、#elif、#else和#endif指令
.................................. ..................692
27.2在Tomcat中配置對SSI的支持......692
27.3小結............. ......................................694
27.4思考題........ .......................................694
第28章Tomcat閥..... ...........................697
28.1 Tomcat閥簡介...................................697
28.2客戶訪問日誌閥..... ...........................698
28.3遠程地址過濾閥................. ...............700
28.4遠程主機過濾閥............................. ...701
28.5錯誤報告閥........................................702
28.6小結................................................. ..703
28.7思考題............................................ ...703
第29章在Tomcat中配置SSL...........705
29.1 SSL簡介....................... .....................705
29.1.1加密通信....................... ........706
29.1.2安全證書...............................706
29.1.3 SSL握手...............................707
29.2在Tomcat中使用SSL........... ...........709
29.2.1準備安全證書.......................709
29.2.2配置SSL連接器............. ......710
29.2.3訪問支持SSL的Web站點..711
29.3小結............................. ......................712
29.4思考題........................ .......................712
第30章用ANT工具管理Web應用..715
30.1安裝配置ANT .......... ........................715
30.2創建build.xml文件................... .......715
30.3運行ANT....................................... ...721
30.4小結............................................ .......722
30.5思考題....................................... ........723
第31章使用Log4J進行日誌操作.....725
31.1 Log4J簡介........................ ................725
31.1.1 Logger組件...........................726
31.1.2 Appender組件.......................727
31.1.3 Layout組件................ ...........728
31.1.4 Logger組件的繼承性...........729
31.2 Log4J的基本使用方法............ .........730
31.2.1創建Log4J的配置文件........730
31.2.2在程序中使用Log4J ............731
31.3在helloapp應用中使用Log4J .........734
31.4小結................................. ..................736
31.5思考題............................ ...................736
第32章Velocity模板語言...................739
32.1獲得與Velocity相關的類庫............739
32.2 Velocity的簡單例子.........................740
32.2. 1創建Velocity模板................740
32.2.2創建擴展VelocityViewServlet的
Servlet類.................... ...............740
32.2.3發布和運行基於Velocity的Web
應用....................................... .....741
32.3註釋.......................................... .........743
32.4引用...................................... .............743
32.4.1變量引用............................... 744
32.4.2屬性引用...............................744
32.4.3方法引用....... ........................746
32.4.4正式引用符................... ........747
32.4.5安靜引用符...........................747
32.4.6轉義符. ..................................747
32.4.7大小寫替換......... ..................748
32.5指令............................. ......................748
32.5.1 #set指令..................... ...........748
32.5.2字面字符串...........................750
32.5.3 #if指令.......... ........................750
32.5.4比較運算.................... ...........751
32.5.5 #foreach循環指令................752
32.5.6 #include指令........ .................753
32.5.7 #parse指令.......................... ..754
32.5.8 #macro指令..........................754
32.5.9轉義VTL指令....... ...............755
32.5.10 VTL的格式.........................756
32.6其他特徵...........................................756
32.6.1數學運算...............................756
32.6.2範圍操作符............ ...............757
32.6.3字符串的連接.......................757
32.7小結. .................................................. 758
32.8思考題............................................... 758
第33章創建嵌入式Tomcat服務器...761
33.1將Tomcat嵌入Java應用.................761
33.2創建嵌入了Tomcat的Java示範程序
.... .................................................. .......763
33.3終止嵌入式Tomcat服務器..............766
33.3.1調用Tomcat類的stop()方法終止
服務器........ ................................766
33.3.2通過SHUTSDOWN命令終止服
務器....... .....................................766
33.4運行嵌入式Tomcat服務器...... ........768
33.5小結....................................... ............771
33.6思考題.................................. .............771
附錄A server.xml文件..........................775
A.1配置Server元素................................776
A.2配置Service元素..... ..........................777
A.3配置Engine元素................. ..............777
A.4配置Host元素............................. ......778
A.5配置Context元素..............................778
A.6配置Connector元素..........................779
A.7配置Executor元素................. ...........781
附錄B web.xml文件.............................783
B. 1配置過濾器.........................................785
B.2配置Servlet ........................................786
B.3配置Servlet映射.. ..............................787
B.4配置Session.............. ..........................787
B.5配置Welcome文件清單................ ....787
B.6配置Tag Library.................................788
B.7配置資源引用.... .................................788
B.8配置安全約束.......... ...........................789
B.9配置安全驗證登錄界面.............. .......789
B.10配置對安全驗證角色的引用...........790
附錄C XML簡介................ ..................791
C.1 SGML、HTML與XML的比較......791
C.2 DTD文檔類型定義....... .....................792
C.3有效XML文檔以及簡化格式的XML文
檔............... ..........................................793
C.4 XML中的常用術語...........................795
C.4.1 URL、URN和URI ............. ..795
C.4.2 XML命名空間.......................795
附錄D書中涉及軟件獲取途徑......... ..799
作者介紹
孫衛琴是中國知名IT 作家和Java 專家,畢業於上海交通大學,隨後主要從事基於Java 的軟件開發工作,在此期間還從事Java 方面的培訓和諮詢工作。2002 年開始Java 技術領域的創作,文風清晰嚴謹、深入淺出,深受讀者歡迎,其多部作品的銷量在同類書籍中一度位居全國榜首。