Servlet - ServletConfig相关

1. ServletConfig对象是Servlet的专属配置对象, 每个Servlet都单独拥有一个ServletConfig对象, 用来获取web.xml文件中的配置信息

2. 使用: 

// 获取ServletConfig对象
    ServletConfig sc = this.getServletConfig();

// 获取web.xml中配置的数据
    sc.getInitParameter(name);
    
    web.xml中的写法: 
    <servlet>
        <servlet-name></servlet-name>
        <servlet-class></servlet-class>
        <init-param>
            <param-name>name</param-name>
            <param-value>value</param-value>
        </init-param>
    </servlet>

猜你喜欢

转载自www.cnblogs.com/mpci/p/12658884.html