l
当多个客户端并发访问同一个Servlet时,web服务器会为每一个客户端的访问请求
创建一个线程,并在这个线程上调用Servlet的service方法,因此service方法内如
果访问了同一个资源的话,就有可能引发线程安全问题。
l
ServletConfig是servlet在进行初始化时,对servlet的初始化参数进行封装后的对象,jdbc数据库的配置,struts的配置等等,都是这样配置
这样配置的好处是可以在配置文件中不断进行改动,但是在servlet就不需要进行改动了。
<servlet-name>ServletDemo2</servlet-name>
<servlet-class>huawei.oss.ServletDemo2</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>denghongwei</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>123456</param-value>
</init-param>
</servlet>
<servlet-class>huawei.oss.ServletDemo2</servlet-class>
<init-param>
<param-name>name</param-name>
<param-value>denghongwei</param-value>
</init-param>
<init-param>
<param-name>password</param-name>
<param-value>123456</param-value>
</init-param>
</servlet>
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
ServletConfig config = this.getServletConfig();
Enumeration<String> e = config.getInitParameterNames();
while(e.hasMoreElements()){
String name =e.nextElement();
String value = config.getInitParameter(name);
System.out.println(name +"="+value);
}
throws ServletException, IOException {
ServletConfig config = this.getServletConfig();
Enumeration<String> e = config.getInitParameterNames();
while(e.hasMoreElements()){
String name =e.nextElement();
String value = config.getInitParameter(name);
System.out.println(name +"="+value);
}
}