<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    城市獵人

    在一網(wǎng)情深的日子里,誰能說得清是苦是甜,只知道確定了就義無反顧
    posts - 1, comments - 7, trackbacks - 0, articles - 89

    Servlet總結(jié)

    Posted on 2009-07-18 11:57 sailor 閱讀(431) 評論(0)  編輯  收藏 所屬分類: java
     

    The Container initializes a servlet by loading the class, invoking the servlet’s no-arg constructor, and calling the servlet’s init() method.

    1 The init() method (which the developer can override) is called only once in a servlet’s life, and always before the servlet can service any client requests.

    2 The init() method gives the servlet access to the Serv-letConf g and ServletContext objects, which the servlet needs to get information about the servlet conf guration and the web app.

    3 The Container ends a servlet’s life by calling its destroy() method.

    4 Most of a servlet’s life is spent running a service() method for a client request.

    5 Every request to a servlet runs in a separate thread! There is only one instance of any particular servlet class.

    6 Your servlet will almost always extend javax.servlet.http.HttpServlet, from which it inherits an implementation of the service() method that takes an HttpServletRequest and an HttpServletResponse.

    7 HttpServlet extends javax.servlet.GenericServlet—an abstract class that implements most of the basic servlet methods.

    8 GenericServlet implements the Servlet interface.

    9 Servlet classes (except those related to JSPs) are in one of two packages: javax.servlet or javax.servlet.http.

    10 You can override the init() method, and you must override at least one service method (doGet(), doPost(), etc.)

    The HttpServlet’s doGet() and doPost() methods take an HttpServletRequest and an HttpServletResponse.

    1 The service() method determines whether doGet() or doPost() runs based on the HTTP Method (GET, POST, etc.) of the HTTP request.

    2 POST requests have a body; GET requests do not, although GET requests can have request parameters appended to the request URL (sometimes called “the query string”).

    3 GET requests are inherently (according to the HTTP spec) idempotent. They should be able to run multiple times without causing any side effects on the server. GET requests shouldn’t change anything on the server. But you could write a bad, non-idempotent doGet() method.

    4 POST is inherently not idempotent, so it’s up to you to design and code your app in such a way that if the client sends a request twice by mistake, you can handle it.

    5 If an HTML form does not explicitly say “method=POST”, the request is sent as a GET, not a POST. If you do not have a doGet() in your servlet, the request will fail.

    6 You can get parameters from the request with the getParameter(“paramname”) method. The return value is always a String.

    7 If you have multiple parameter values for a given param-eter name, use the getParameterValues(“paramname”) method that returns a String array.

    8  You can get other things from the request object including headers, cookies, a session, the query string, and an input stream

    Post與Get區(qū)別:
    1. Get用于從服務(wù)端獲取數(shù)據(jù),Post用于向服務(wù)器端提交數(shù)據(jù);
    2. Get提交后,參數(shù)保留在瀏覽器地址欄,Post不會;
    3. Get提交時,URL會帶參數(shù),Post不會。因?yàn)閁RL是保存到http協(xié)議頭部。而Post參數(shù)保存到http協(xié)議Body中
    4. Get容易產(chǎn)生重復(fù)提交,Post不會。

     

    You use the Response to send data back to the client.

    1 The most common methods you’ll call on the response object (HttpServletResponse) are setContentType() and getWriter().

    2 Be careful—many developers assume the method is getPrintWriter(), but it’s getWriter().

    3 The getWriter() method lets you do character I/O to write HTML (or something else) to the stream.

    4 You can also use the response to set headers, send errors, and add cookies.

    5 In the real world, you’ll probably use a JSP to send most HTML responses, but you may still use a response stream to send binary data

    (like a JAR f le, perhaps) to the client.

    6 The method you call on your response for getting a binary stream is getOutputStream().

    7 The setContentType() method tells the browser how to handle the data coming in with the response. Typical content types are “text/html”, application/pdf”, and “image/jpeg”.

    8 You don’t have to memorize content types (also known as MIME types).

    9 You can set response headers using addHeader() or setHeader(). The difference depends on whether the header is already part of the response. If it is, setHeader() will replace the value, but addHeader will add an additional value to the existing response. If the header is not already part of the response, then setHeader() and addHeader() behave in exactly the same way.

    10 If you don’t want to respond to a request, you can redirect the request to a different URL. The browser takes care of sending the new request to the URL you provide.

    11 To redirect a request, call sendRedirect(aStringURL) on the response.

    12 You cannot call sendRedirect() after the response is committed! In other words, if you’ve already written something to the stream, it’s too late to do a redirect.

    13 A request redirect is different from a request dispatch. A request dispatch (covered more in another chapter) happens on the server, while a redirect happens on the client. A request dispatch hands the request to another component on the server, usually within the same web app. A request redirect simply tells the browser to go a different URL

    主站蜘蛛池模板: eeuss影院ss奇兵免费com| 99久久99久久免费精品小说| 亚洲成人一区二区| 亚洲AV无码AV男人的天堂不卡| 国内精品乱码卡1卡2卡3免费| 亚洲精品资源在线| 最近免费字幕中文大全视频| 亚洲精品美女久久久久9999| 亚洲w码欧洲s码免费 | 久久夜色精品国产噜噜亚洲a| 综合在线免费视频| 亚洲va在线va天堂成人| 毛片免费全部免费观看| 亚洲av永久无码嘿嘿嘿| 最近免费中文字幕4| 亚洲日韩精品无码专区加勒比 | 青青草国产免费国产是公开| 亚洲A∨精品一区二区三区| 免费一级全黄少妇性色生活片 | 三年片在线观看免费观看大全中国 | 亚洲国产aⅴ成人精品无吗| 性做久久久久免费看| 在线观看亚洲专区| 亚洲AV无码乱码精品国产| 一个人看www免费高清字幕| 亚洲午夜精品一级在线播放放| 国产高清视频免费在线观看| 国产A在亚洲线播放| 精品无码AV无码免费专区| 亚洲视频在线观看网站| 永久免费的网站在线观看| 亚洲成av人在线观看网站| 亚洲av区一区二区三| 一二三区免费视频| 久久亚洲精品AB无码播放| 久久福利资源网站免费看| 亚洲色偷精品一区二区三区| 亚洲av日韩片在线观看| 国产在线精品观看免费观看| 精品日韩亚洲AV无码一区二区三区 | 久久久久久曰本AV免费免费|