zoukankan      html  css  js  c++  java
  • ServletConfig

    public interface ServletConfig {
        public String getServletName();//获取Servlet在web.xml文件中的配置名称,即<servlet-name>指定的名称
        public ServletContext getServletContext();//用来获取ServletContext对象
        public String getInitParameter(String name);//用来获取在web.xml中配置的初始化参数,通过参数名来获取参数值
        public Enumeration<String> getInitParameterNames();//用来获取在web.xml中配置的所有初始化参数名称
    
    }

    tomcat在创建Servlet对象时,会自动将初始化参数封装到ServletConfig对象中,传递给init()方法,就可以使用了

    如:

    <servlet>
            <servlet-name>sf</servlet-name>
            <servlet-class>com.sflik.servlet.HelloServlet</servlet-class>        
            <init-param>
            <param-name>pname</param-name>
            <param-value>pvalue</param-value>
            </init-param>        
        </servlet>
    @Override
        public void init(ServletConfig config) throws ServletException {
            System.out.println(config.getInitParameter("pname")); 
            System.out.println(config.getInitParameter("pvalue")); 
            Enumeration e = config.getInitParameterNames();
            while(e.hasMoreElements()){
                System.out.println(e.nextElement());
            }
        }

     GenericServlet实现了ServletConfig接口,拥有ServletConfig的方法

  • 相关阅读:
    spring的工厂类
    spring的基于XML方式的属性注入
    github上传大于100M的文件报错
    fatal: HttpRequestException encountered
    VAR 学习笔记3
    You are my great sunshine
    warning: LF will be replaced by CRLF in
    术语词汇
    XGBoost学习笔记2
    四大基本算法思想
  • 原文地址:https://www.cnblogs.com/sflik/p/4564864.html
Copyright © 2011-2022 走看看