标签:init-param context-param java ee load-on-startup init
(1)lode-on-startup,该Servlet会在项目启动时被调用(主要调用起init方法,为安全着想,一般不应该为该Servlet建立URL映射),一般用作预处理一些数据,或者配合多线程建立定时任务
<servlet><pre name="code" class="html"><span style="font-family:Arial, Helvetica, sans-serif;"> </span><span style="font-family:SimSun;font-size:12px;"> <servlet-name>FirstServlet</servlet-name></span><servlet-class>com.hunhun.FirstServlet</servlet-class> <!-- 1 表示多个预处理Servlet的启动顺序--> <lode-on-startup>1</lode-on-startup> </servlet>
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> </servlet>
2.1 多个init-param
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>author</param-name> <param-value>hunhun</param-value> </init-param> <init-param> <param-name>versioon</param-name> <param-value>1.0</param-value> </init-param> </servlet>
Enumeration<String> names = this.getServletConfig().getInitParameterNames(); while(names.hasMoreElements()){ //name为每个init-param名字 String name=names.nextElement(); }(3)context-param,全局配置信息,可在多个Servlet中使用
<servlet> <servlet-name>FirstServlet</servlet-name> <servlet-class>com.hunhun.FirstServlet</servlet-class> <init-param> <param-name>encoding</param-name> <param-value>utf-8</param-value> </init-param> <init-param> <param-name>author</param-name> <param-value>hunhun</param-value> </init-param> <init-param> <param-name>versioon</param-name> <param-value>1.0</param-value> </init-param> </servlet> <context-param> <param-name>date</param-name> <param-value>2011-12-3 10:30:24</param-value> </context-param>
标签:init-param context-param java ee load-on-startup init
原文地址:http://blog.csdn.net/hunhunpanda/article/details/41170053