JavaWEB - Servlet

1.Tomcat简介:

 

 2.Java Web 的结构

 

3.Servlet:

 

 

 

 

4.ServletConfig 

A servlet configuration object used by a servlet container to pass information to a servlet during initialization.

@Override
    public void init(ServletConfig arg0) throws ServletException {
        System.out.println("init ....");

        System.out.println(arg0.getInitParameter("name"));
        System.out.println(arg0.getInitParameter("password"));

        // 获得初始化参数的名字
        Enumeration<String> enumeration = arg0.getInitParameterNames();
        while (enumeration.hasMoreElements()) {
            String value = (String) enumeration.nextElement();
            System.out.println(value);
        }
    }

 

5.ServletContext

 

// 获得ServletContext
        ServletContext context = config.getServletContext();
        System.out.println(context.getInitParameter("driver"));

        // 获得application 参数
        Enumeration<String> enumerationContext = context.getInitParameterNames();
        while (enumerationContext.hasMoreElements()) {
            String value = (String) enumerationContext.nextElement();
            System.out.println(value);
        }

        // 获得部署文件的绝对路径
        System.out.println(context.getRealPath("/index.jsp"));
        // 获得当前的web根路径名称
        System.out.println(context.getContextPath());

 

posted on 2018-04-01 14:16  pjlhf  阅读(123)  评论(0编辑  收藏  举报

导航