I followed a servlet tutorial, created a servlet(HelloServlet
) in a java file named HelloServlet.java
.Compiled the .java file to HelloServet.class
. My questions
1) Is the servlet's name is same with servlet file(name for the compiled java file) or should be different?
This is because on the example I followed, he set the servlet-name different from the servlet-class
, in web.xml
.
servlet-name is not related to servlet class name. it is used to link the servlet class with the servlet mapping. In the below example i have used servlet-name XXX while declaring a servlet and then mapped it with the test url by giving the same servlet-name in the mapping file.
<servlet>
<servlet-name>XXX</servlet-name>
<servlet-class>className</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>XXX</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>