${status.count}
colspan="2">
* Tile 的 attribute 在 HTML 中可透過 getAttribute 取得,ex:
* 視 js 為 .txt
[Java]
- for each
- @Override
- from 1.5
- 但在 1.5 不支援 interface 使用,因此必須使用 1.6。
- 20120615
[JSP]
* Reference
- 关于解决Java @Override的问题
* Directive
- <%@ %>
- 使用指令元素include來包括其它網頁內容時,會在轉譯時期就決定轉譯後的Servlet內容,是一種靜態的指定方式。
- 標籤的使用,則是執行時期動態將別的網頁包括進來進行回應的方式,使用的網頁與被包括的網頁,各自都生成一個獨立的Servlet。
* 宣告、Scriptlet 與運算式元素
- Declare: <%! %>
- Scriptlet: <% %>
- Expression: <%= %>
- 容器預設會使用同一個Servlet實例來服務不同使用者的請求,每個請求是一個執行緒,而<%!與%>間宣告的變數對應至類別變數成員,因此會有執行緒共用存取的問題。
- <%與%>之間所包括的內容,將被轉譯為Servlet原始碼_jspService()方法中的內容。注意!運算式元素中不用加上分號(;)。這個運算式元素在轉譯為Servlet之後,會在_jspService()中產生以下的陳述句:out.print(new Date());
* JSP 生命週期
- 注意到_jspInit()、_jspDestroy()與_jspService()方法名稱上有個底線,表示這些方法是由容器轉譯時維護,你不應該重新定義這些方法。如果想要作些JSP初始化或收尾動作,則應定義jspInit()或jspDestroy()方法。
* 深入 <jsp:usebean>、<jsp:setproperty> 與 <jsp:getproperty>
- 如果你使用標籤時沒有指定scope,則預設「只」在page範圍中尋找JavaBean,找不到就建立新的JavaBean物件(不會再到request、session與application中尋找)。
* Reference
- 語言技術:Servlet/JSP Gossip
Session
* Passing session specific data through the application object is not safe.
* Different sessions could override each other.
* When the browser is closed and started again, a new session object is created but the application is still the same.
* Flow:
- When the first request comes from a browser on a new host, the server makes the beginning of a new session, and assigns a new session ID.
- The session ID will be then send to the browser as cookie.
- The browser will remember this ID, and send the ID back to the server in the subsequent requests.
- When the server receives a request with session ID in them, it knows this is a continuation of an existing session.When the server receives a request from a browser on a new host (request without a session ID), the server not only creates a new session ID, it also creates a new session object associated with the session ID.
* If there is no subsequent request coming back for a long time for a particular session ID, that session will be timed out. After the session has been timed out, if the browser comes back again with the associated session ID, the server will give an invalid session error.
Cookie
* Cookie: A small amount of information sent by a Web server to a Web browser, saved by the browser, and sent back to the server later.
* Cookies are transmitted inside the HTTP header.
* Cookies are actually saved to the hard disk of Web browser user's machines.
* I s a technology, not a language.
* To put dynamic data into a Web document with Java statements embedded in special HTML tags.
* The embedded Java statements will be executed by the JSP enabled Web server, not by the Web browser.
* There are two key processes involved in serving a JSP page:
- Compilation: A JSP page must be compiled into a Java Servlet class, before it can be executed. The server can compile a JSP page in real-time when the page is requested for the first time, if the page is not pre-compiled.
- Execution: When a JSP page is requested, its compiled class will be executed on the server. The server will send back the output of the execution, not the content of the JSP page.
* Example for hello.jsp: What happened here was that Tomcat, the JSP Web server, has translated hello.jsp into hello_jsp.java, and compiled it to hello_jsp.class.
* The Java file, hello_jsp.java, shows that:
- hello_jsp is a sub class of org.apache.jasper.runtime.HttpJspBase, which is a sub class of javax.servlet.http.HttpServlet.
- The important method in hello_jsp is _jspService() with two objects listed as parameters: one represents the Servlet request, and the other represents the Servlet response.
- The static content of hello.jsp is translated into out.write() statements.
- The embedded Java statement in hello.jsp is copied directly.
* JSP page is served by the JSP Web server by executing the JSP Servlet Java class translated from the JSP page.
* Java statements embedded in JSP pages will translated into _jspService() method of a special Servlet class.
* pre-defined objects ready for the embedded Java statements: - out: The output stream to collect dynamic data to be mixed into the final Web document.
- this: The instance of the special Servlet class.
- request: An HttpServletRequest object representing the request received from the Web browser.
- response: An HttpServletResponse object representing the response to be delivered back to the Web browser.
- session: An HttpSession object representing the concept of linking multiple trips of requests and response into a single process unit.
- application: A ServletContext object representing the concept of grouping Servlets into a single application.
* A new session will be established, if this JSP page is requested for the first time. Subsequent requests will share the same session.
* session: A object provided by the JSP server to hold information and methods common to all JSP pages running under one session. The session object must be an instance of a class that implements the javax.servlet.http.HttpSession interface defined by the J2EE specification.
* Reference
- JavaServer Pages (JSP)
- Execution Context
.經Java平台技術 主要用來產生Dynamic Web constent 包括HTML DHTML XHTML 和XML
.Dynamic Web 技術標準似ASP PHP ...etc
.HTML 中加入Java片段(Scriptlet)和JSP標籤=JSP網頁
.Servlet/JSP container 收到client 發出的request 首先執行其中的程式片段 然後將執行結果以HTML 格式回應給客戶端
.其中程式片段可是:操作資料庫 重新定向網頁 發送email,etc
.所有程式操作都在Server執行 網路上傳送給Client的僅是得到的結果 與client的瀏覽器無關 因此JSP稱為Server-Side Language
.是類似於ASP的嵌入型scripting Language
.當JSP 被轉譯成Servlet時內容主要包含三部份:
-- _jspInit(): 當JSP網頁一開始執行時 最先執行此方法 因此我們通常會把初始化的工作寫在此方法中
-- _jspDwstroy(): JSP網頁最後執行的方法
-- _jspService(): JSP網頁最主要的程式都是在此方法
.JSP網頁主要可以分為:
-- Template Data: JSP container 不處理的部份 ex: HTML的內容 會直接傳送到Client 執行
-- Elements: 需經JSP container處理 而大部份elements都是以XML做為語法基礎 並且大小寫必須一致
|