作者shorttime (乡民)
看板java
标题[问题]Servlet和container的相关问题
时间Sat Jan 14 15:16:34 2012
关於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)