美文网首页
【Java】【web】web.html映射配置文件

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

作者: JerichoPH | 来源:发表于2017-04-09 18:07 被阅读64次

    web.html影射配置文件

    <!-- web.html -->
    <!-- servletDemo5 -->
    <servlet>
        <servlet-name>ServletDemo5</servlet-name>
        <servlet-class>com.demo.ServletDemo5</servlet-class>
        <!-- 配置信息 -->
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </servlet>
    
    <servlet-mapping>
        <servlet-name>ServletDemo5</servlet-name>
        <url-pattern>/demo5</url-pattern>
    </servlet-mapping>
    
    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映射配置文件

          本文链接:https://www.haomeiwen.com/subject/onodattx.html