[問題]有關Servlet和container的問題
關於servlet和container,
我在網路上有看到相關描述:
During initialization stage of the Servlet life cycle,
the web container initializes the servlet instance
by calling the init() method.
Each request is serviced in its own separate thread.
The Web container calls the service() method of the servlet
for every request.
The service() method determines the kind of request being made
and dispatches it to an appropriate method to handle the request.
Finally, the Web container calls the destroy() method that takes
the servlet out of service.
(來源出處:http://en.wikipedia.org/wiki/Java_Servlet )
我有3個基本問題想請教大家一下,
問題一:
假設我有一個servlet的程式,
程式碼如下:
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class HelloServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {
PrintWriter out = res.getWriter();
out.println("Hello, world!");
out.close();
}
}
那....在container的程式內部,
是不是會執行"類似"下列這些動作呢?
HelloServlet servlet = new HelloServlet();
servlet.init();
servlet.servlet();
servlet.destroy();
問題二:
從上述的HelloServlet程式碼是不是可以看出,
HelloServlet是直接使用HttpServlet的service(),init()和destroy(),
而沒有對這兩個method做任何override和overload的動作呢?
問題三:
請問....HttpServlet的service(),init()和destroy()完整程式碼內容,
在哪個網站可以查的出來嗎?
因為我想藉由程式碼的內容得知,
一個servlet的程式做初始化,處理request,做destroy的詳細動作.
還麻煩各位不吝惜指教一下,
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.135.248.33
※ 編輯: shorttime 來自: 220.135.248.33 (01/14 15:18)
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):