首页 > 代码库 > ServletConfig

ServletConfig

<servlet>

<servlet-name>Demo</servlet-name>

<servlet-class>com.Demo</servlet-class>

<init-param>

<param-name>xx</param-name>

<param-value>123</param-value>

</init-param>


<init-param>

<param-name>bbb</param-name>

<param-value>111</param-value>

</init-param>

</servlet>


public class Demo extends HttpServlet {

public void doGet(HttpServletRequest request, HttpServletResponse response)

throws ServletException, IOException {


//获取指定的初始化参数

String value = http://www.mamicode.com/this.getServletConfig().getInitParameter("xxx");

response.getOutputStream().write(value.getBytes());


//获取所有的初始化参数

Enumeration e = this.getServletConfig().getInitParameterNames();

while (e.hasMoreElements()) {

String name = (String) e.nextElement();

value = http://www.mamicode.com/this.getServletConfig().getInitParameter(name);

response.getOutputStream().write((name + "=" + value + "<br/>").getBytes());

}

}

}


ServletConfig