How to set up the root servlet in Tomcat 6? [duplicate]

风格不统一 提交于 2019-11-29 07:12:26

deploy an web app with context root /
and set servlet-mapping in web.xml as

<servlet-mapping>
  ..
  <url-pattern>/</url-pattern>
</servlet-mapping>  

This is an old thread, but Jigar Joshi's answer wasn't working for me on Tomcat 8.0 and Servlet 3.1. So I used the following mapping in web.xml.

<servlet-mapping>
    <servlet-name>myServlet</servlet-name>
    <url-pattern></url-pattern>
</servlet-mapping>

In section 12.2, Servlet 3.0 specification states that:

The empty string ("") is a special UR L pattern that exactly maps to the application's context root, i.e., requests of the form http://host:port//. In this case the path info is ’ / ’ and the servlet path and context path is empty string (““).

I did the following in my web.xml. I mapped servlet as index.html.

<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>myservlet</welcome-file>
</welcome-file-list>

and then the servlet itself:

<servlet>
<description></description>
<display-name>myservlet</display-name>
<servlet-name>myservlet</servlet-name>
<servlet-class>myservlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>myservlet</servlet-name>
<url-pattern>/index.html</url-pattern>
</servlet-mapping>
McDowell

From the Tomcat 6 context configuration documentation:

Context elements may be explicitly defined ... (snip) ... in individual files (with a ".xml" extension) in the $CATALINA_BASE/conf/[enginename]/[hostname]/ directory. The name of the file (less the .xml extension) will be used as the context path. Multi-level context paths may be defined using #, e.g. foo#bar.xml for a context path of /foo/bar. The default web application may be defined by using a file called ROOT.xml.

You must also map the servlet in that application to the root path (/).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!