Tomcat 4.1 ROOT servlet mapping.

F

F. H.

Around a year ago I remember it being absolutely impossible to
configure tomcat to have something like:

http://www.example.com/

map to a servlet; you have to have http://www.example.com/index.jsp
instead.

Anyways, if I just want to have http://www.example.com/index be a
servlet what do I put in web.xml? It seems like servlet names like
/index won't work in the welcome-file-list.

As a last resort I could put index.html in the welcome-file-list and
have index.html redirect to the /index servlet, but this means
everytime a user loads http://www.example.com/ they are first
redirected to /index.html and then redirected to /index. It's really
stupid that two redirects should be necessary because of Tomcat's lack
of configurability.

Ugh, I hate Tomcat and don't know why such a simple thing that's so
easy with Apache+Perl is so hard with a supposedly "superior
technology." Why can't I just have http://www.example.com/ be a
servlet?
Anyways, I'll settle for http://www.example.com/index if someone can
show me how to configure Tomcat to serve /index when
http://www.example.com/ is requested.

Also, has the situation improved with Tomcat 5?
 
W

William Brogden

Around a year ago I remember it being absolutely impossible to
configure tomcat to have something like:

http://www.example.com/

map to a servlet; you have to have http://www.example.com/index.jsp
instead.

Anyways, if I just want to have http://www.example.com/index be a
servlet what do I put in web.xml? It seems like servlet names like
/index won't work in the welcome-file-list.

As a last resort I could put index.html in the welcome-file-list and
have index.html redirect to the /index servlet, but this means
everytime a user loads http://www.example.com/ they are first
redirected to /index.html and then redirected to /index. It's really
stupid that two redirects should be necessary because of Tomcat's lack
of configurability.

Ugh, I hate Tomcat and don't know why such a simple thing that's so
easy with Apache+Perl is so hard with a supposedly "superior
technology." Why can't I just have http://www.example.com/ be a
servlet?
Anyways, I'll settle for http://www.example.com/index if someone can
show me how to configure Tomcat to serve /index when
http://www.example.com/ is requested.

Also, has the situation improved with Tomcat 5?

Tomcat has always had a servlet mapped to /

<!-- The mapping for the default servlet -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

Just look at your server.xml, replace the "default" with the name of
the servlet you want, and there you are. Its easy with a "superior
technology" - but you have to do some reading.
 
F

F. H.

William Brogden said:
Tomcat has always had a servlet mapped to /

<!-- The mapping for the default servlet -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>

Just look at your server.xml, replace the "default" with the name of
the servlet you want, and there you are. Its easy with a "superior
technology" - but you have to do some reading.

But the mapping to '/' is really a mapping to '/*' --- that is, EVERY
url is then mapped to my servlet so now http://www.example.com/asdfxyz
maps to my servlet instead of giving a 404. The serving of all
filetypes and responses is broken this way because now my servlet
wants to be the default one that serves *.gif, *.html, 404 errors, and
so forth. I suppose it might be possible to have my servlet check if
the request is for something other than '/' and then pass the request
to the org.apache.catalina.servlets.DefaultServlet class if it is....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top