黑马程序员 08 Servlet 学习笔记 02 生命周期与servletCofig

                                                  ------- android培训java培训、期待与您交流! --------

Content-Type: text/x-zim-wiki
Wiki-Format: zim 0.4
Creation-Date: 2013-01-13T00:13:38+08:00


====== Servlet 02 生命周期 ======
Created Sunday 13 January 2013


Servlet 的生命周期<工作流程>
<线程不安全>
WEB收到客户端的servlet访问请求后
1. 当servlet第一次被调用的时候,会触发init()函数,该函数会把servlet的实例装载到内存  init()只会被调用一次
2. 然后去调用servlet 的 service () 函数<创建HttpServletRequest 和 HttpServletResponse >
3. 当第二次后访问该servlet 则直接调用 service() 函数
4. 当WEB应用 reload 或者 关闭 都会去调用 destory ()函数,该函数就会去销毁servlet;

public class TestServlet implements Servlet {
public void destroy() {
// 销毁servlet 该函数之执行一次
}
public ServletConfig getServletConfig() {
// 获得serletConfig对象 
return null;
}
public String getServletInfo() {
// 获得servletInfo信息
return null;
}
public void init(ServletConfig arg0) throws ServletException {
// 启动servlet  该函数只执行一次
}
public void service(ServletRequest arg0, ServletResponse arg1)
throws ServletException, IOException {
// 该函数执行多次 我们的逻辑代码就写在这里
}
}
====== Servlet 04 ServletConfig ======
Created Sunday 13 January 2013


ServletConfig对象
改对象主要是用于读取servlet的一些信息
配置当前servlet信息
<servlet>
<init-param><!-- 只能被该servlet读取-->
<param-name>encoding</param-name>
<param-value>utf-8</param-vlaue>
</init-param>
</servlet>
全局设置配置信息
<context-param>
</context-param>
读取servletConfig配置信息
用配置名读取  this.getServletConfig().getInitParameter("encoding");
读取所有配置  Enumeration<String> names =this.getServletConfig.getInitParameterNames();
略!while(names.next.....)遍历name集合 取值
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值