Monday, May 4, 2015

Configure the Servlet URL Mapping

Configure the Servlet URL mapping in "web.xml"
Our <form>'s action attribute refers to relative URL "echo", which has to be mapped to the
EchoServlet.class in the web application deployment descriptor file "WEB-INF\web.xml":
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<!-- To save as <CATALINA_HOME>\webapps\helloservlet\WEB-INF\web.xml -->
<servlet>
<servlet-name>HelloWorldServlet</servlet-name>
<servlet-class>mypkg.HelloServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>EchoServletExample</servlet-name>
<servlet-class>mypkg.EchoServlet</servlet-class>
</servlet>
<!-- Note: All <servlet> elements MUST be grouped together and
placed IN FRONT of the <servlet-mapping> elements -->
<servlet-mapping>
<servlet-name>HelloWorldServlet</servlet-name>
<url-pattern>/sayhello</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>EchoServletExample</servlet-name>
<url-pattern>/echo</url-pattern>
</servlet-mapping>
</web-app>


No comments:

Post a Comment

Contact Form

Name

Email *

Message *