标签:
1、获得 servlet配置的servletname
2、获得servlet 配置的 getInitParameter(“keyname”)
3、获得servlet配置的 所有的 key
package cn.jiemoxiaodi.servlet_config; import java.io.IOException; import java.util.Enumeration; import javax.servlet.Servlet; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; public class BServlet implements Servlet { private ServletConfig config; public void destroy() { } public ServletConfig getServletConfig() { return this.config; } public String getServletInfo() { return null; } public void init(ServletConfig config) throws ServletException { this.config = config; } public void service(ServletRequest req, ServletResponse res) throws ServletException, IOException { // 1 // System.out.println(this.config.getServletName()+"==="+this.config.getInitParameterNames()); // 2\ System.out.println(this.config.getInitParameter("a")); // 3\Enumeration em = this.config.getInitParameterNames(); // while (em.hasMoreElements()) { // String key = (String) em.nextElement(); // System.out.println(key); // } // 4\ServletContext sc= this.config.getServletContext(); } }
标签:
原文地址:http://www.cnblogs.com/jiemoxiaodi/p/5107911.html