JavaWeb基础学习第六天

IDE和地址区别
“/” ==“Web应用\WebRoot\WEB-INF\classes”
“/” == “Web应用”

public void doGet(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException {
        //取得当前对象的字节码对象
        Class clazz = this.getClass();
        //取得当前对象的类加载器
        ClassLoader cl = clazz.getClassLoader();
        //通过类加载器加载资源文件

        InputStream is = cl.getResourceAsStream("WEB-INF/classes/config.properties");
        //全路径      物理路径而不是IDE的路径                               day06/WEB-INF/classes/config.properties                      

        //InputStream is = cl.getResourceAsStream("WEB-INF/classes/cn/incast/web/config.properties");
        //全路径      物理路径而不是IDE的路径                               day06/WEB-INF/classes/cn/itcast/web/config.properties                      

        //InputStream is = cl.getResourceAsStream("WEB-INF/config.properties");
        //全路径      物理路径而不是IDE的路径                               day06/WEB-INF/config.properties            

        Properties props = new Properties();
        props.load(is);
        System.out.println(props.getProperty("email"));

        /*传统方式
        InputStream is = new FileInputStream("src/config.properties");
        //全路径                     tomcat/bin/src/config.properties
        Properties props = new Properties();
        props.load(is);
        System.out.println(props.getProperty("email"));
        */

        /*ServletContext context = this.getServletContext();
        InputStream is = context.getResourceAsStream("/doc/config.properties");
        //全路径      物理路径而不是IDE的路径                          day06/WEB-INF/doc/config.properties 
        Properties props = new Properties();
        props.load(is);
        System.out.println(props.getProperty("email"));
        */
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值