Sorry for beginner's questions but I wonder how can I set the root servlet in Tomcat 6? For example I want to access my servlet on
localhost:8080
, not on
localhost:8080/myservlet
Thanks!
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>
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 calledROOT.xml
.
You must also map the servlet in that application to the root path (/
).