标签:
<servlet> <servlet-name>helloServlet</servlet-name> <servlet-class>servlettest.HelloServlet</servlet-class> <!-- 配置Servlet 初始化参数, 且该节点必须在load-on-startup 的前面 --> <init-param> <!-- 参数名 --> <param-name>username</param-name> <!-- 参数值 --> <param-value>root</param-value> </init-param> <init-param> <param-name>password</param-name> <param-value>12345</param-value> </init-param> <!-- 指定Servlet被创建的时机 --> <load-on-startup>-1</load-on-startup> </servlet>
@Override public void init(ServletConfig servletConfig) throws ServletException { System.out.println("This is init"); String user = servletConfig.getInitParameter("user"); System.out.println("user=" + user); Enumeration<String> parameterNmaes = servletConfig.getInitParameterNames(); while (parameterNmaes.hasMoreElements()){ String name = parameterNmaes.nextElement(); String value = servletConfig.getInitParameter(name); System.out.println(name + " = " + value); } String servletName = servletConfig.getServletName(); System.out.println(servletName); }
标签:
原文地址:http://www.cnblogs.com/shi-yi-ge/p/5352340.html