三本鎮(zhèn)坑:
- Head First Servlets and JSP 2nd Edition: 密碼: p5yt
- Head First Servlets and JSP 中文版 第1版: 密碼: 3x7q
- Head First Servlets and JSP 中文版 第2版: 密碼: qbad
- JavaServer Pages 2.3 Specification
Table of Contents (Summary)
Intro xix
1. Why use Servlets & JSPs: an introduction 1
2. Web App Architecture: high-level overview 37
3. Mini MVC Tutorial: hands-on MVC 67
4. Being a Servlet: request AND response 93
5. Being a Web App: attributes and listeners 147
6. Conversational state: session management 223
7. Being a JSP: using JSP 281
In the end, a JSP is just a servlet
Making a JSP that displays how many times it's been accessed
She deploys and tests it
The JSP doesn't recognize the Counter class
Use the page directive to import packages
But then Kim mentions "expressions"
Expressions become the argument to an out.print()
Kim drops the final bombshell...
Declaring a variable in a scriptlet
8. Script-free pages: scriptless JSP 343
9. Custom tags are powerful: using JSTL 439
10. When even JSTL is not enough: custom tag development 499
11. Deploying your web app: web app deployment 601
12. Keep it secret, keep it safe: web app security 649
13. The Power of Filters: wrappers and filters 701
14. Enterprise design patterns: patterns and struts 737
A Appendix A: Final Mock Exam 791
i Index
引子 xix
1 為什么使用Servlets & JSP: 前言與概述
2 Web應(yīng)用體系結(jié)構(gòu):高層概述
3 MVC迷你教程:MVC實(shí)戰(zhàn)
4 作為Servlet:請求和響應(yīng)
5 作為Web應(yīng)用:屬性和監(jiān)聽者
6 會話狀態(tài):會話管理
7 作為JSP:使用JSP
8 沒有腳本的頁面:無腳本的JSP
9 強(qiáng)大的定制標(biāo)記:使用JSTL
10 JSTL也有力不能及的時候:定制標(biāo)記開發(fā)
11 部署Web應(yīng)用:Web應(yīng)用部署
12 要保密,要安全:Web應(yīng)用安全
13 過濾器的威力:過濾器和包裝器
14 企業(yè)設(shè)計模式:模式和struts
A 附錄A:最終模擬測驗(yàn)
i 索引
7
首先是一個例子:
Counter.java
package com.example.model;
public class Counter{
private static int count;
public static synchronized int getCount() {
count++;
return count;
}
}
BasicCounter.jsp
<%@ page import="com.example.model.*" %>
<html>
<body>
<%= Counter.getCount() %>
</body>
</html>
接下來編譯部署
javac -d classes src\com\example\model\Counter.java
將編譯后的class文件與jap文件频丘,放在Tomcat中办成,啟動Tomcat,在瀏覽器中觀測結(jié)果搂漠。
然后問題就來了:
- Counter.java寫的什么迂卢?
因?yàn)椴欢甹ava語言,只能猜了桐汤。
聲明而克,以下編譯單元為包c(diǎn)om.example.model;
聲明并定義公有類Counter;
聲明私有靜態(tài)整數(shù)型類字段count;
聲明并定義公有靜態(tài)異步整數(shù)型方法getCount;
count自加并返回
- package是什么?
A package declaration
包聲明出現(xiàn)在普通編譯單元中怔毛,用于指示編譯單元所屬的包员萍。
- <%@ page import="com.example.model.*" %> 是什么?
import 是 page 眾多屬性之一拣度,page 是 3 種 directive 之一充活。
Directives are messages to the JSP container. Directives have this syntax:
<%@ directive { attr=”value” }* %>
指令為你提供了一條途徑,可以在頁面轉(zhuǎn)換時向容器提供特殊的指示蜡娶。
The page directive defines a number of page dependent properties and communicates these to the JSP container.
<%@ page page_directive_attr_list %>
page_directive_attr_list ::= { language=”scriptingLanguage”}
{ extends=”className” }
{ import=”importList” }
{ session=”true|false” }
{ buffer=”none|sizekb” }
{ autoFlush=”true|false” }
{ isThreadSafe=”true|false” }
{ info=”info_text” }
{ errorPage=”error_url” }
{ isErrorPage=”true|false” }
{ contentType=”ctinfo” }
{ pageEncoding=”peinfo” }
{ isELIgnored=”true|false” }
{ deferredSyntaxAllowedAsLiteral=”true|false”}
{ trimDirectiveWhitespaces=”true|false”}
An import attribute describes the types that are available to the scripting environment. The value is as in an import
declaration in the Java programming language, a (comma separated) list of either a fully qualified Java programming language type name denoting that type, or of a package name followed by the .* string, denoting all the public types
declared in that package.