You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Ken Bowen <kb...@als.com> on 2007/09/29 23:33:58 UTC

How to specify a default context?

Hi all,

When no contexts for a Host are specified in server.xml, but all are 
placed in the META-INF of their respective apps,
how does one specify one of them as the default Context for that Host?

http://tomcat.apache.org/tomcat-5.5-doc/config/context.html doesn't seem 
to say what to do:

    path:    .......If you specify a context path of an empty string
    (""), you are defining the /default/ web application for this Host,
    which will process all requests not assigned to other Contexts. The
    value of this field must not be set except when statically defining
    a Context in server.xml, as it will be inferred from the filenames
    used for either the .xml context file or the docBase.

Using the simple Tomcat sample 
(http://tomcat.apache.org/tomcat-5.5-doc/appdev/sample/sample.war),  I 
set up a test setting:

Host definition from server.xml:

      <Host appBase="webapps" name="strong-brain.com" unpackWARs="true"
    autoDeploy="true">
              <Alias>www.strong-brain.com</Alias>
              <Context path="/manager"
    docBase="/opt/tomcat5/server/webapps/manager" privileged="true"
    debug="0"/>
              <Context path="/admin"
    docBase="/opt/tomcat5/server/webapps/admin" privileged="true"
    debug="0"/>
              <Logger className="org.apache.catalina.logger.FileLogger"
    prefix="strong-brain.com." suffix=".txt" timestamp="true"/>
      </Host>

Applications in tomcat5/webapps:

    ROOT  sample  sample.war  sample2

[sample2 is just a slightly edited copy of sample]
Out of the box, neither has a context.xml in META-INF. 
Connecting to http://strong-brain.com/sample or 
http://strong-brain.com/sample2 gives the expected result, and connecting
to    http://strong-brain.com/   yields the Tomcat manager (Is that 
because it is the first context listed in Host??)

Despite the prohibition on using 'path=...' in Contexts in META-INF, I 
tried putting this in webapps/sample/META-INF/context.xml:

 <Context path="" debug="10" reloadable="true" cookies="true"/>

It didn't have any effect.  In particular, connecting to 
http://strong-brain.com/  still yielded the manager.

So how can I make sample or sample2 the default webapp for this Host, 
running when the connection to http://strong-brain.com/  is made???

Thanks,
Ken Bowen




---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to specify a default context?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Szabolcs Márton [mailto:marton.szabolcs@gmail.com] 
> Subject: Re: How to specify a default context?
> 
> maybe try this, in server.xml, in tomcat6
> <Context path="" docBase="YOUR_CONTEXT_HERE" debug="0" />

Please read the docs before posting.  In current versions of Tomcat, do not ever put <Context> elements inside server.xml.  Do it the documented way, and save yourself a lot of headaches.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to specify a default context?

Posted by Szabolcs Márton <ma...@gmail.com>.
Hi

maybe try this, in server.xml, in tomcat6

<Context path="" docBase="YOUR_CONTEXT_HERE" debug="0" />

after this, every request at http://host will served by the context you
specified here.
No any changes neccessary, as i remember.

regards
Szabi



2007/9/30, Caldarale, Charles R <Ch...@unisys.com>:
>
> > From: Ken Bowen [mailto:kbowen@als.com]
> > Subject: Re: How to specify a default context?
> >
> > Since I plan to use http://tuckey.org/urlrewrite/ to
> > rewrite URLs, and since "/" will rewrite to "/myapp/",
> > then the request htpp://myhost/ will ending up causing
> > myapp to handle the request.
>
> Yes, using a filter or valve to forward or redirect requests to the
> desired URI should work.
>
> - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>

RE: How to specify a default context?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ken Bowen [mailto:kbowen@als.com] 
> Subject: Re: How to specify a default context?
> 
> Since I plan to use http://tuckey.org/urlrewrite/ to 
> rewrite URLs, and since "/" will rewrite to "/myapp/",
> then the request htpp://myhost/ will ending up causing
> myapp to handle the request.

Yes, using a filter or valve to forward or redirect requests to the
desired URI should work.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to specify a default context?

Posted by Ken Bowen <kb...@als.com>.
Absolutely all correct, including the design flaws (partly due to the 
learning curve, partly to the
process of pasting together non-web software which has such embedded 
knowledge -- needs
to be overcome).

However, after my 3rd cup of coffee this morning, it occurrs to me that 
what I'm after is not
really that myapp be the /default/ application, but that myapp be the 
application which runs
when the server receives the request http://myhost, where myhost is the 
name of the HOST
in which myapp is a Context.  As a Context for HOST, the request 
http://myhost/myapp/
causes myapp to run.  Since I plan to use 
http://tuckey.org/urlrewrite/ to rewrite URLs, 
and since "/" will rewrite to "/myapp/",  then the request htpp://myhost/
will ending up causing myapp to handle the request.

Is this sound?  Am I missing something here?

Thanks,
Ken

Caldarale, Charles R wrote:
>> From: Ken Bowen [mailto:kbowen@als.com] 
>> Subject: Re: How to specify a default context?
>>
>> Is there no other way, one which leaves the app with its 
>> original name?
>>     
>
> Place your webapp outside of the <Host>'s appBase directory, and put
> your <Context> element in conf/Catalina/[host]/ROOT.xml with a docBase
> attribute pointing to the absolute file system location of your webapp.
>
>   
>> Because of the convoluted way I've written the app, renaming 
>> it to ROOT has bad effects.
>>     
>
> If you have coded the app to use a specific URL to refer to itself, then
> it can't be the default app, can it?  If you've coded I/O paths within
> the app, then you've violated the servlet spec, which expects that
> webapps can be deployed on devices without file systems.  Either are
> major design flaws that should never make it into a production system.
>
>  - Chuck
>
>
> THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
> MATERIAL and is thus for use only by the intended recipient. If you
> received this in error, please contact the sender and delete the e-mail
> and its attachments from all computers.
>
> ---------------------------------------------------------------------
> To start a new topic, e-mail: users@tomcat.apache.org
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>
>
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


RE: How to specify a default context?

Posted by "Caldarale, Charles R" <Ch...@unisys.com>.
> From: Ken Bowen [mailto:kbowen@als.com] 
> Subject: Re: How to specify a default context?
> 
> Is there no other way, one which leaves the app with its 
> original name?

Place your webapp outside of the <Host>'s appBase directory, and put
your <Context> element in conf/Catalina/[host]/ROOT.xml with a docBase
attribute pointing to the absolute file system location of your webapp.

> Because of the convoluted way I've written the app, renaming 
> it to ROOT has bad effects.

If you have coded the app to use a specific URL to refer to itself, then
it can't be the default app, can it?  If you've coded I/O paths within
the app, then you've violated the servlet spec, which expects that
webapps can be deployed on devices without file systems.  Either are
major design flaws that should never make it into a production system.

 - Chuck


THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY
MATERIAL and is thus for use only by the intended recipient. If you
received this in error, please contact the sender and delete the e-mail
and its attachments from all computers.

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to specify a default context?

Posted by Ken Bowen <kb...@als.com>.
Is there no other way, one which leaves the app with its original name?
Because of the convoluted way I've written the app, renaming it to ROOT 
has bad effects.

Thanks,
Ken Bowen

Hassan Schroeder wrote:
> On 9/29/07, Ken Bowen <kb...@als.com> wrote:
>
>   
>> When no contexts for a Host are specified in server.xml, but all are
>> placed in the META-INF of their respective apps,
>> how does one specify one of them as the default Context for that Host?
>>     
>
> Name it ROOT (directory) or ROOT.war, as appropriate.
>
> HTH,
>   

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: How to specify a default context?

Posted by Hassan Schroeder <ha...@gmail.com>.
On 9/29/07, Ken Bowen <kb...@als.com> wrote:

> When no contexts for a Host are specified in server.xml, but all are
> placed in the META-INF of their respective apps,
> how does one specify one of them as the default Context for that Host?

Name it ROOT (directory) or ROOT.war, as appropriate.

HTH,
-- 
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org