Head First Servlet & JSP . 慢讀與空想筆記

三本鎮(zhèn)坑:

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應用體系結構:高層概述
3 MVC迷你教程:MVC實戰(zhàn)
4 作為Servlet:請求和響應
5 作為Web應用:屬性和監(jiān)聽者
6 會話狀態(tài):會話管理
7 作為JSP:使用JSP
8 沒有腳本的頁面:無腳本的JSP
9 強大的定制標記:使用JSTL
10 JSTL也有力不能及的時候:定制標記開發(fā)
11 部署Web應用:Web應用部署
12 要保密,要安全:Web應用安全
13 過濾器的威力:過濾器和包裝器
14 企業(yè)設計模式:模式和struts
A 附錄A:最終模擬測驗
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,在瀏覽器中觀測結果。

然后問題就來了:

  1. Counter.java寫的什么?

因為不懂java語言,只能猜了。

聲明,以下編譯單元為包com.example.model;
聲明并定義公有類Counter;
    聲明私有靜態(tài)整數(shù)型類字段count;
    聲明并定義公有靜態(tài)異步整數(shù)型方法getCount;
        count自加并返回
  1. package是什么?

A package declaration

包聲明出現(xiàn)在普通編譯單元中,用于指示編譯單元所屬的包。

  1. <%@ page import="com.example.model.*" %> 是什么?

import 是 page 眾多屬性之一,page 是 3 種 directive 之一。

Directives are messages to the JSP container. Directives have this syntax:

<%@ directive { attr=”value” }* %>

指令為你提供了一條途徑,可以在頁面轉換時向容器提供特殊的指示。

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.

最后編輯于
?著作權歸作者所有,轉載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容