编程语言
首页 > 编程语言> > 关于Servlet程序中ServletConfig接口与ServletContext里面初始化参数的遍历

关于Servlet程序中ServletConfig接口与ServletContext里面初始化参数的遍历

作者:互联网

 

  当Servlet程序中ServletConfig接口与ServletContext里面初始化参数比较多的时候,我们采用枚举的方式来更快的操作

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    ServletConfig config = this.getServletConfig();
    Enumeration<String> names = config.getInitParameterNames();
    while(names.hasMoreElements()){
        String nextElement = names.nextElement();
        String parameter = config.getInitParameter(nextElement);
        System.out.println(nextElement+":"+parameter);
    }

}

 

标签:String,Servlet,config,nextElement,names,ServletContext,ServletConfig
来源: https://www.cnblogs.com/attention-wechat/p/15378666.html