package cn.itcast;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.Enumeration;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
//servletConfig对象:用于封装servlet的配置信息
//在实际开发,有一些东西不适合在servlet中写死,这类数据就可以通过配置方式给servlet,例如
//servlet采用哪个码表、servlet连接哪个库,servlet哪个配置文件
public class ServletDemo extends HttpServlet {
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// 得到指定的
String value = this.getServletConfig().getInitParameter("data1");
System.out.println(value);
// 得到所有的
Enumeration e = this.getServletConfig().getInitParameterNames();
while (e.hasMoreElements()) {
String name = (String) e.nextElement();
String value1 = this.getServletConfig().getInitParameter(name);
System.out.println(name+"..="+value1);
}
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}
}