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

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

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

    城市獵人

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

    Servlet總結(jié)

    Posted on 2009-07-18 11:57 sailor 閱讀(432) 評(píng)論(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不會(huì);
    3. Get提交時(shí),URL會(huì)帶參數(shù),Post不會(huì)。因?yàn)閁RL是保存到http協(xié)議頭部。而Post參數(shù)保存到http協(xié)議Body中
    4. Get容易產(chǎn)生重復(fù)提交,Post不會(huì)。

     

    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

    主站蜘蛛池模板: 亚洲伊人久久大香线蕉结合| 亚洲第一黄色网址| 最近2022中文字幕免费视频| 日韩视频免费在线观看| 最近2019中文免费字幕在线观看 | 亚洲人成网7777777国产 | 国产又大又粗又长免费视频| 在线免费观看国产| 1000部禁片黄的免费看| 日本片免费观看一区二区| 91麻豆最新在线人成免费观看 | 又粗又大又猛又爽免费视频| 日本在线高清免费爱做网站| av无码久久久久不卡免费网站| 无码乱肉视频免费大全合集| 国产一卡2卡3卡4卡无卡免费视频 国产一卡二卡3卡四卡免费 | 亚洲?v女人的天堂在线观看| 亚洲女人被黑人巨大进入| 亚洲免费日韩无码系列 | 国产亚洲A∨片在线观看| 亚洲国产精品无码久久一区二区 | 国产亚洲精品线观看动态图| 亚洲精品国产精品乱码不99| 亚洲AV日韩AV天堂一区二区三区| 久久久亚洲AV波多野结衣| 中文有码亚洲制服av片| 边摸边吃奶边做爽免费视频网站| 一级做a爱片特黄在线观看免费看| 一级人做人爰a全过程免费视频| 伊人免费在线观看高清版| 日韩精品久久久久久免费| 免费国产成人高清在线观看网站| 在线观看免费污视频| 亚洲欧洲久久av| 久久亚洲精精品中文字幕| 亚洲一区无码中文字幕乱码| 亚洲AV色无码乱码在线观看| 国产精品极品美女自在线观看免费 | 亚洲国产精品久久久久婷婷软件 | 久久精品国产亚洲AV| 国产精品美女免费视频观看|