zoukankan      html  css  js  c++  java
  • ServletConfig笔记

    package com.hailu;
    
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import java.io.IOException;
    import java.util.Enumeration;
    
    /**
     *
     * Servletconfig
     *      作用:
     *          方便每一个servlet获取自己单独的属性配置
     *      特点:
     *          1、每一个servlet单独拥有一个servletConfig对象
     *      使用:
     *          获取对象
     *          ServletConfig config = this.getServletConfig();
     *          获取值
     *          config.getInitParameter("china");
     *          获取所有的key值
     *          config.getInitParameterNames();
     */
    public class ServletConfigServlet extends HttpServlet {
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            this.doGet(request,response);
        }
    
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            //获取对象
            ServletConfig config = this.getServletConfig();
            String value = config.getInitParameter("china");
            System.out.println(value);
            //获取所有的key
            Enumeration<String> initParameterNames = config.getInitParameterNames();
            while (initParameterNames.hasMoreElements()){
                String key = initParameterNames.nextElement();
                String value2 = config.getInitParameter(key);
                System.out.println(key+"----"+value2);
            }
        }
    }
  • 相关阅读:
    javascript中的require、import和export模块文件
    MFC CDHtmlDialog 加载本地资源
    互斥和信号量
    CString与char *互转总结
    MFC消息-自定义消息
    Python网络爬虫之Scrapy框架(CrawlSpider)
    scrapy中selenium的应用
    UA池和代理池
    抓取js动态生成的数据分析案例
    scrapy框架的日志等级和请求传参
  • 原文地址:https://www.cnblogs.com/yanghailu/p/12797874.html
Copyright © 2011-2022 走看看