先來講講WebApp的目錄結構吧
在你的應用目錄下 應該會有(1)htm,html,jsp檔
(2)WEB-INF目錄
(3)META-INF目錄
(4)其它目錄,如:images。
WEB-INF 應有
(1)web.xml檔 ,作為Server的設定檔(2)classes 目錄,用於保存JavaBean、Servlet等,可根據需要創建包。
(3)lib目錄,用於保存jar檔。
Example:
假設你創了一個目錄 名為Demo 如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
<display-name>demo</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
</welcome-file-list>
</web-app>
index.html 內容
<h1>Welcome to hello page.</h1>打開瀏覽器 輸入 http://localhost:8080/demo/ 則會出現
Servlet:
在此我只以三張圖來表達Traditional Server
Client 對 Server 送出request , Server 回應 response 此稱為三向交握
實際就是 你送出什麼請求 伺服器 就將你需要的 網站 回應給你
Servlet
Client對Server端發出request Servlet接收後作處理 會在向server 發出發出httprequest
最後才將資訊最後才將資訊response到client端 就好像有個控制器幫你處理後端事物
引用自: Java網站應用
Spring-MVC
MVC(Model View Control)架構 可以說是又把 Servlet的工作細分 分別去處理事物
對於這方面觀念 請參考 http://openhome.cc/Gossip/ServletJSP/
請 耐心看完 容器、Servlet 與 JSP
不可不看的好文:簡介Web應用程式
HTTP Method
GET將資料傳送到WebServer端
會將資料附加在URL上作為QueryString的一部分
從?開始&隔開
POST
將資料傳送到WebServer端
會將資料隱藏在message-body中
不受QueryString 長度限制 允許大量傳輸
PUT
從客戶端向Server傳送pata取代指定的文件內容
又可稱為 Update
HEAD
與GET同,只是不回傳資源本文(not requesting resorce)
OPTIONS
可使Server回傳支持的HTTP請求 可測試Server是否正常
DELETE
請求Server刪除Request_URI所標示的resource
TRACE
回顯Server收到的請求 主要用來測試、診斷
ContentType V.S pageEncoding
ContentType 指定的是Browser最終所見到的網頁編碼pageEncoding 指定的是 編寫時所使用編碼
編譯三階段
1)編寫:java,html,jsp........... > pageEncoding
2)Bytecode:一律將編譯過後的檔案轉成 UTF-8
3)Browser:由Client端看到的效果 > ContentType






沒有留言:
張貼留言