码迷,mamicode.com
首页 > 其他好文 > 详细

ServletConfig 可以做啥

时间:2016-01-07 01:04:10      阅读:149      评论:0      收藏:0      [点我收藏+]

标签:

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();
        
    }

}

ServletConfig 可以做啥

标签:

原文地址:http://www.cnblogs.com/jiemoxiaodi/p/5107911.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!