# 1/13 Servlet 觀念 ###### tags: `Servlet` # 4-114 Data Sharing介紹 ServletRequest個別(專屬)1對1 httpSession個人(生命週期較長)1對1多次 Servlet(Context)(多種)生命週期最長(環境) 多對1 Attribute(屬性) Enumeration 用法:強迫轉型 用字串變數接  set(寫入)get(讀取) # 4-115 sharing Data Request階段:ServletRequest Session階段:httpSession Application階段:ServletContext  # 4-116 RequestDispatcher分派協調 RequestDispatcher交出去再拿回來 forward交出去給別的負責 include:Client->servlet1->servlet2->servlet1->Client 都需要傳入參數 # 4-117.119 如何取得RequestDispatcher javax.servlet.ServletContext路徑參數要用/開頭 javax.servlet.ServletRequest相對路徑 httpSession:   getRequestDispatcher:``` The difference between this method and ServletContext.getRequestDispatcher(java.lang.String) is that this method can take a relative path.``` getRequestDispatcher盡量用/開頭 ServletContext:多了getNamedDispatcher用註冊的名子去輸入 # 4-118 Servlet間資料傳輸 removeAttribute:將物件由request # 4-123 Servlet Context介面 需在同一個Context 分四大類 初始參數,檔案資源,屬性,日誌紀錄 # 4-125 ServletContext抓取變數 Enumeration # 4-126 使用ServletContext  # 4-128 Events & Listeners 生命週期 起來關掉 屬性 改變 # 4-130 Events & Listeners介面 and registered註冊 # 4-145 check uncheck check檢查完往外丟 uncheck不用特別檢查往外丟 # 4-147 Exception宣告與操作 包裝好往外丟 servletException(ss) root exception # 4-150ProgramaticErrorHandlingServlet trycatch 子查詢在前面 越特殊規格在前面 # 4-160 logging GenericServlet方法 log(紀錄) # 4-165 state與Sessions Sessions用途:購物車中記錄消費者的購物項目 # 4-166 伺服器記錄使用者的方式 如果使用者不用cookies 就必須用URL # 4-168 取得Session方式 getSession(boolean create) 裡面是false就不會新增 ``` If create is false and the request has no valid HttpSession, this method returns null. ``` 裡面是true ``` this request or, if there is no current session and create is true, returns a new session. ``` # 4-169 HttpSession Vertor(只能放物件) 類似陣列 # 4-170 處理Session events HttpSessionBindingListener:不需要再wem.xml中設定 # 4-172 HttpSessionListener 紀錄最高最低人數功能 # 4-180 web.xml設定Session Timeout ``` <session-config> <session-timeout>1</session-timeout> </session-config> ``` # Cookies 記錄在Client端上的小檔案 容量有限 不要存放機密資料 # URL rewrite 會自動偵測Coolies有沒有關
×
Sign in
Email
Password
Forgot password
or
By clicking below, you agree to our
terms of service
.
Sign in via Facebook
Sign in via Twitter
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
New to HackMD?
Sign up