You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Johnson, Garrett" <Jo...@cbsnews.com> on 2002/12/13 20:00:59 UTC

Difficult sections in server.xml and web.xml...

Ladies and Gentlemen:

I'm afraid I can't seem to wrap my head around a few things in the web.xml
and server.xml files in configuring Tomcat:

In server.xml:

* What does the <Host> node mean?  If I set <Host name="localhost"> does
that make a difference than if I set it for <Host name="foobar">?  Does the
name attribute have real significance or is it just an ID?

In web.xml, (sitting in a context directory,):

* For the <servlet> node:
	* Is the servlet-name attribute merely an ID?
	* What is the display-name attribute for?

* For the <servlet-mapping> node:
	* Is the servlet-name attribute ALSO merely an ID?
	* What is the syntax for the url-pattern attribute?  Can I use
wildcards?  Reg. Expressions?

* Finally, is there any relationship between the <Context> node in the
server.xml file and the web.xml?  Or is the only dependency that the web.xml
file needs to be in docbase/WEB-INF, where docbase is the value of the
docbase attribute in the <Context> nodes?

Thanks in advance for any assistance y'all can provide.


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Difficult sections in server.xml and web.xml...

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Fri, 13 Dec 2002, Johnson, Garrett wrote:

> Date: Fri, 13 Dec 2002 14:00:59 -0500
> From: "Johnson, Garrett" <Jo...@cbsnews.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>
> To: 'Tomcat Users List' <to...@jakarta.apache.org>
> Subject: Difficult sections in server.xml and web.xml...
>
> Ladies and Gentlemen:
>
> I'm afraid I can't seem to wrap my head around a few things in the web.xml
> and server.xml files in configuring Tomcat:
>
> In server.xml:
>
> * What does the <Host> node mean?  If I set <Host name="localhost"> does
> that make a difference than if I set it for <Host name="foobar">?  Does the
> name attribute have real significance or is it just an ID?
>

The <Host> element lets you ask Tomcat to answer requests for more than
one host name, within the same instance of Tomcat.  (NOTE -- your DNS
server must map the various host names to the IP address of your server).
The name must match the DNS name that is assigned.

When a request comes in, Tomcat checks the "Host" header and finds a
matching <Host> element.  If there are none, it sends the request to
whichever host name you've declared as the "defaultHost" on the
surrounding <Engine> element.

In an out-of-the-box Tomcat install, there is a single <Host> element
named "localhost", and this is also the defaultHost setting.  That's why
it is able to answer requests for any valid hostname for your server.

For more info on server.xml configuration values:

  http://jakarta.apache.org/tomcat/tomcat-4.1-doc/config/

> In web.xml, (sitting in a context directory,):
>
> * For the <servlet> node:
> 	* Is the servlet-name attribute merely an ID?
> 	* What is the display-name attribute for?
>

The servlet name is an ID.  The display name element is available for use
by GUI tools that help you assemble webapps -- it doesn't have any direct
influence on the execution of your app.

> * For the <servlet-mapping> node:
> 	* Is the servlet-name attribute ALSO merely an ID?

Yes -- it is the ID that is used to match this mapping to a particular
servlet with the same name.

> 	* What is the syntax for the url-pattern attribute?  Can I use
> wildcards?  Reg. Expressions?

See Chapter 11 of the Servlet Specification:

  http://java.sun.com/products/servlet/download.html

or one of the large numbers of books about servlet programming.  There's
also more information in the Application Developer's Guide included with
Tomcat, or available online at:

  http://jakarta.apache.org/tomcat/tomcat-4.1-doc/appdev/


>
> * Finally, is there any relationship between the <Context> node in the
> server.xml file and the web.xml?

There can be a <Context> element for each web application that is deployed
inside Tomcat.  (You don't need an explicit <Context> element for webapps
that are automatically deployed in the $CATALINA_HOME/webapps
subdirectory, if the default settings work for you).

Within a webapp directory, you must obey the requirements of the servlet
spec for file organization, which includes having the web.xml file in the
/WEB-INF subdirectory.

>  Or is the only dependency that the web.xml
> file needs to be in docbase/WEB-INF, where docbase is the value of the
> docbase attribute in the <Context> nodes?

As you'll see in the configuration docs pointed to above, you can also use
an absolute pathname in the docBase attribute, and have your webapp
anyplace you like in the filesystem.

>
> Thanks in advance for any assistance y'all can provide.
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Difficult sections in server.xml and web.xml...

Posted by Justin Ruthenbeck <ju...@nextengine.com>.
At 11:00 AM 12/13/2002, you wrote:
>* For the <servlet> node:
>         * Is the servlet-name attribute merely an ID?
>         * What is the display-name attribute for?

The servlet-name attribute is a UNIQUE user-defined name that you use to 
identify that particular servlet.  This value must match the servlet-name 
value in the <servlet-mapping> tag.

The display name, on the other hand, does not have to be unique.  It is 
used in other places (management applications, user output, etc) to 
identify the servlet in a "friendly" way.  Think of the servlet-name as 
your primary key and the display-name as your regular name.

>* For the <servlet-mapping> node:
>         * Is the servlet-name attribute ALSO merely an ID?
>         * What is the syntax for the url-pattern attribute?  Can I use
>wildcards?  Reg. Expressions?

As I mentioned, the servlet-name here matches that in the <servlet> 
node.  The syntax for url-pattern is pretty limited.  You're limited to the 
wildcard char ("*") and actual url strings.  See the servlet spec for more 
details.

>* Finally, is there any relationship between the <Context> node in the
>server.xml file and the web.xml?  Or is the only dependency that the web.xml
>file needs to be in docbase/WEB-INF, where docbase is the value of the
>docbase attribute in the <Context> nodes?

The server.xml file contains all of the Tomcat-specific settings that allow 
Tomcat to provide the services your app requires.  The spec does not 
dictate how these vendor-specific settings are set, so Tomcat does it this 
way (with the notion of "context" and "host", etc).  Other vendors do it in 
some very different ways.  Everything your app needs to run is found in the 
web.xml -- everything to make the container run is in server.xml.  The only 
thing these two share is jndi names (which your application references 
through web.xml and your container creates through it's specific 
scheme).  This is the only relationship.

justin


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>