Home  >  Forum  >  JSP, Servlet
Post New Query

Servlet 4 web.xml



Asked on July 11, 2018
Hi, I am working on Servlet 4 project. Can anyone provide me sample Servlet 4 web.xml?


Replied on July 11, 2018
Find the sample Servlet 4 web.xml. It will be supported by Java 9 and Tomcat 9.

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="4.0" xmlns="http://xmlns.jcp.org/xml/ns/javaee"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee 
   http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd">

<display-name>Web Project</display-name>
        <context-param>
     <param-name>MyParam</param-name>
     <param-value>MyParamValue</param-value>
        </context-param>
        <servlet>
           <servlet-name>MyServlet</servlet-name>
           <servlet-class>com.demo.MyServlet</servlet-class>
           <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
           <servlet-name>MyServlet</servlet-name>
           <url-pattern>/MyServlet/*</url-pattern>
        </servlet-mapping>

        <filter>
           <filter-name>MyFilter</filter-name>
           <filter-class>com.demo.MyFilter</filter-class>
           <init-param>
             <param-name>test-param</param-name>
             <param-value>Initialization Parameter</param-value>
           </init-param>
        </filter>

        <filter-mapping>
           <filter-name>MyFilterr</filter-name>
           <url-pattern>/*</url-pattern>
        </filter-mapping>

        <listener>
           <listener-class>com.demo.MyListener</listenerclass>
        </listener>
</web-app> 


Write Answer







©2019 concretepage.com | Privacy Policy | Contact Us