【Java】【web】web.html映射配置文件

web.html影射配置文件




    ServletDemo5
    com.demo.ServletDemo5
    
    
        encoding
        UTF-8
    



    ServletDemo5
    /demo5

public class ServletDemo5 extends HttpServlet {

    private ServletConfig config;
    
    @Override
    public void init(ServletConfig config) throws ServletException {
        this.config = config;
    }
    
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        // 方式:1
         String encoding = this.config.getInitParameter("encoding");
         System.out.println(encoding);
        
        // 方式:2
        String encoding2 = super.getInitParameter("encoding");
        System.out.println(encoding2);
        
        // 方式:3
        String encoding3 = this.getServletConfig().getInitParameter("encoding");
        System.out.println(encoding3);
    }
    
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
    }

}

你可能感兴趣的:(【Java】【web】web.html映射配置文件)