willim

          常用鏈接

          統(tǒng)計

          好友列表

          鏈接

          最新評論

          SERVLET學習筆記(一)

          打算這個星期把SERVLET和JSP復習下,我認為基礎(chǔ)對一個人很重要,所以會經(jīng)常回過頭來看看.
          1.HTTP協(xié)議
          每個做web應用都應該熟悉HTTP協(xié)議吧,如果不熟悉大家找些資料去學學.
          GET: 參數(shù)直接作為一個query string放到URL后面?zhèn)鬟f的.可以是text
          POST:參數(shù)是作為封裝一個請求信息體里的.可以是text和binary
          servlet里有多個方法用來對應處理http協(xié)議的請求方法
          doGet() : link,和直接在瀏覽器中輸入URL
          doPost():? 通過form表單顯示聲明method="post",否則默認為get
          doDelete(): 針對要刪除服務器的某些資源的請求
          doTrace(): 調(diào)試服務器連接的http方式
          doOptions() : The OPTIONS request determines which HTTP methods the server supports and returns an appropriate header. For example, if a servlet overrides doGet, this method returns the following header:
          Allow: GET, HEAD, TRACE, OPTIONS
          doPut() : 針對要向服務器放入新的文件的請求
          doHead(): 針對只要response的Header信息的請求

          當client來一個請求時,doService(HttpServletRequest request, HttpServletResponse response) throws ServletException ,IOException接受這個,并選擇相應的請求選擇相應的方法進行處理

          2.HttpServletResquest介紹
          常用的方法:String getParameter(String name)
          Enumeration getParameterNames()
          String[] getParameterValues(String name)
          String?? getHeader(String name)
          int getIntHeader(String name)
          long getDateHeader(String name)
          Enumeration getHeaderNames()
          String[] getHeaderValus(String name)
          Cookies[] getCookies()

          3.HttpServletResponse介紹
          void setContentType(String type)
          setHeader(String name, String value)
          setIntHeader(String name, int value)
          setDateHeader(String name, long value)
          addHeader(String name, String name)
          addIntHeader(String name, int value)
          addDateHeader(String name ,long value)
          boolean containsHeader(String name)

          PrintWriter getWriter()? //返回字符流
          OutputStream getOutputStream()? //返回字節(jié)流

          void sendRedirect(String URL) //重定向到某個頁面

          void sendError(int sc) //發(fā)生錯誤向客戶端發(fā)送狀態(tài)碼
          void sendError(int sc, String message)

          void addCookie(Cookie cookie) //增加一個cookie

          Cookie(String name, String value) //? cookie的構(gòu)造方法

          4.SERVLET的生命周期
          servlet loading? ---> servlet instantiation ---> call init() ---> call doService handle request ---> call destroy()

          public void init(ServletConfig config) throws ServletException
          如果override這個方法必須先調(diào)用super.init(config)

          public void init() throws ServletException

          public void service() throws ServletException, IOException

          public void destroy() throws ServletException

          posted on 2006-12-25 22:30 willlim 閱讀(437) 評論(0)  編輯  收藏


          只有注冊用戶登錄后才能發(fā)表評論。


          網(wǎng)站導航:
           
          主站蜘蛛池模板: 乡宁县| 萝北县| 宁夏| 社旗县| 谷城县| 灌阳县| 泗洪县| 平山县| 米易县| 诏安县| 巴马| 兴城市| 吐鲁番市| 洛南县| 根河市| 婺源县| 灵寿县| 秦皇岛市| 利津县| 田阳县| 山东| 镇宁| 琼中| 临洮县| 个旧市| 怀集县| 龙州县| 石狮市| 海城市| 金塔县| 六枝特区| 信丰县| 新巴尔虎左旗| 肥西县| 安新县| 淮阳县| 玉龙| 南康市| 中西区| 哈尔滨市| 安宁市|