We know servlet and JSP are same from back doors. JSP is also servlet, so when JSP executed, it first converted into servlet then servlet execution follows.
My question is, if servlet and JSP are same then why we map servlet in web.xml
deployment descriptor file, but we don't map JSP?
It's already mapped in server's own
web.xml
which get applied on all webapps. So you don't need to explicitly register it in all your webapps.In case of e.g. Tomcat, you can find the below JSP servlet related entries in the
/conf/web.xml
file of the Tomcat installation (below line numbers match Tomcat 8.0.26).You see, any request which matches the URL pattern
*.jsp
or*.jspx
will invoke the server's ownJspServlet
which will then do all the JSP works.Tomcat has no knowledge about your "custom" servlets, so you won't find your "custom" servlets in there and you'd need to map them in webapp's own
web.xml
yourself.