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

来源:互联网 发布:最新网络赚钱项目 编辑:程序博客网 时间:2024/05/18 01:28

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

原创粉丝点击