日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

HttpServlet中的service方法

發(fā)布時(shí)間:2025/6/15 52 豆豆
生活随笔 收集整理的這篇文章主要介紹了 HttpServlet中的service方法 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
HttpServlet中的service方法service方法是接口中的方法,servlet容器把所有請求發(fā)送到該方法,該方法默認(rèn)行為是轉(zhuǎn)發(fā)http請求到doXXX方法中,如果你重載了該方法,默認(rèn)操作被覆蓋,不再進(jìn)行轉(zhuǎn)發(fā)操作! HttpServlet的實(shí)現(xiàn)其中關(guān)于service 的實(shí)現(xiàn)如下:protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException{ String method = req.getMethod();if (method.equals(METHOD_GET)) {long lastModified = getLastModified(req);if (lastModified == -1) { // servlet doesn't support if-modified-since, no reason // to go through further expensive logic doGet(req, resp);} else { long ifModifiedSince = req.getDateHeader(HEADER_IFMODSINCE); if (ifModifiedSince < (lastModified / 1000 * 1000)) {// If the servlet mod time is later, call doGet()// Round down to the nearest second for a proper compare// A ifModifiedSince of -1 will always be lessmaybeSetLastModified(resp, lastModified);doGet(req, resp); } else {resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED); }}} else if (method.equals(METHOD_HEAD)) {long lastModified = getLastModified(req);maybeSetLastModified(resp, lastModified);doHead(req, resp);} else if (method.equals(METHOD_POST)) {doPost(req, resp);} else if (method.equals(METHOD_PUT)) {doPut(req, resp);} else if (method.equals(METHOD_DELETE)) {doDelete(req, resp);} else if (method.equals(METHOD_OPTIONS)) {doOptions(req,resp);} else if (method.equals(METHOD_TRACE)) {doTrace(req,resp);} else {//// Note that this means NO servlet supports whatever// method was requested, anywhere on this server.//String errMsg = lStrings.getString("http.method_not_implemented");Object[] errArgs = new Object[1];errArgs[0] = method;errMsg = MessageFormat.format(errMsg, errArgs);resp.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED, errMsg); }}

總結(jié)

以上是生活随笔為你收集整理的HttpServlet中的service方法的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。