简体   繁体   English

servlet映射Tomcat实际上是如何实现的?

[英]servlet mapping how Tomcat does it actually?

I have installed Tomcat and browse to their example http://mylocalhost.com:8080/examples/servlets/servlet/HelloWorldExample 我已经安装了Tomcat并浏览到他们的示例http://mylocalhost.com:8080/examples/servlets/servlet/HelloWorldExample

But when I look at servlet mapping in web.xml here it is for HelloWorldExample 但是当我在web.xml中查看servlet映射时,它是针对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 访问Web项目的URL是

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. 由此可以看出, examples是项目的名称或项目的context root

so when you give the url like http://mylocalhost.com:8080/examples 因此,当您提供类似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. 首先,容器读取deployment descriptor<welcome-file-list>标记,并显示在<welcome-file>下指定<welcome-file>如果存在)。

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. 当您指定此URL http://mylocalhost.com:8080/examples/servlets/servlet/HelloWorldExample ,容器再次在deployment descriptor搜索指定的URL /servlets/servlet/HelloWorldExample ,如果找到一个,则会加载指定的对应类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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