简体   繁体   中英

servlet mapping how Tomcat does it actually?

I have installed Tomcat and browse to their example http://mylocalhost.com:8080/examples/servlets/servlet/HelloWorldExample

But when I look at servlet mapping in web.xml here it is for HelloWorldExample

<servlet-mapping>
    <servlet-name>HelloWorldExample</servlet-name>
    <url-pattern>/servlets/servlet/HelloWorldExample</url-pattern>
</servlet-mapping>

why is examples missing, shouldn't it be instead :

<url-pattern>/examples/servlets/servlet/HelloWorldExample</url-pattern>

"examples" is the folder name of the Project. It's name will be included in the apps path.

The url to access a web project is

http://yourHost:yourPort/yourProjectName

From this you can make out that examples is the name of your project or the context root of your project.

so when you give the url like http://mylocalhost.com:8080/examples

First the container reads the deployment descriptor 's <welcome-file-list> tag and displays the file specified under <welcome-file> if it is present.

when you specify this url http://mylocalhost.com:8080/examples/servlets/servlet/HelloWorldExample the container again searches the deployment descriptor for the specified url /servlets/servlet/HelloWorldExample and if it finds one it loads the corresponding class specified.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM