Servlet tips --init(), destroy() and retrieving information

本文详细介绍了Servlet的生命周期,包括初始化、服务请求处理以及销毁阶段,并重点讲解了在各阶段如何通过不同方法获取配置参数与请求参数。同时,还探讨了在Servlet中处理GET和POST请求参数的具体方式。

1. CGI Evnironment Variable: request.getXxx..

2. get initiial parameter: ServlietConfig.getInitParameter(para_name);//parameter in web.xml

3. init() is guaranteed to be called and completed before the servlet handles its first request: when the server starts, when the servlet is first requested but before the service() is invoked, when at the request of the server administrator  

4. in the destroy() method, a servlet should free any resources it has acquired that will not be garbage collected. and it also gives a servlet a chance to write out its unsaved cached information or any persistent information that should be read during the next call to init(). If the server crashed, destroy() may not work.

5. getParameter(..): get request parameters as part of its query string(GET) or as encoded POST data. (and there is getParameterValues(..) for the parameter which has more than 1 value. (Begin with Servlet API 2.2,  you can use same parameter in query string and POST valus, then use getParameterValues(..).

6. getRequestURL, getRequestURI and so on

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值