servlet获取web.xml中配置的初始化参数

在web.xml中我们配置的参数如下:


        GetInitParameterServlet
        servlet.GetInitParameterServlet

        
            username
            admin
        

        
            password
            123456
        
        
    

    
        GetInitParameterServlet
        /servlet/GetInitParameterServlet
    

那么在Servlet中,我们如果需要获取初始化参数,就继承以下init方法,在这里调用如下方法进行获取:

@Override
    public void init() throws ServletException {
        String username = this.getInitParameter("username");
        String password = this.getInitParameter("password");
    }



你可能感兴趣的:(java,web,servlet)