<context> problem. I am confused.....

Posted on 2004-11-04
Last Modified: 2010-03-04
In tomcat.
I have the following code in server.xml

<Context path="" docBase="ROOT" debug="0" />
<Context path="/DEMO" docBase="DEMO" debug="0" />

What if I have another folder called "DEMO" under "ROOT"(webapp/ROOT/DEMO)?
I don't really know what's the difference between "setting up another webapp" and "move everything under ROOT"

Please give me advice.

Thank you.
Question by:tsongwei
    LVL 8

    Expert Comment

    you can have another folder under ROOT. but this means whatever jsp/servlets you would be having inside ROOT will all be sharing the same configuration parameters for ROOT. This also means you cannot have a different web.xml in DEMO under ROOT. This also means when the ROOT web application is stopped using the Tomcat Manager then all your files under ROOT/DEMO will be accessible.

    in a nut shell,

    "setting up another webapp"
    is basically creating a new play area for your application where ur jsp/servlets can will share all the configuration data specific to the new webapp and any changes to any other web app will not affect this. and u r giving yourself more flexibility in maintaining this web application like start/stop, security, Resources this web app needs to use ........

    and "move everything under ROOT"
    mean basically u r putting everything under the control of ROOT webapp. your jsp/servlets will share all the configuration specific to ROOT and any change to the ROOT configuration data will affect your jsp/servlets also. if ROOT is stopped/started it will affect your jsp/servlets also ..........

    Context descriptors allow defining all aspects and configuration parameters of a Context, such as naming resources and session manager configuration. It should be noted that the docBase specified in the Context element can refer to either the .WAR or the directory which will be created when the .WAR is expanded or the .WAR itself.

    check this out also

    hope this helps

    LVL 8

    Expert Comment

    >>> web application is stopped using the Tomcat Manager then all your files under ROOT/DEMO will be accessible.

    sorry this line should be

    web application is stopped using the Tomcat Manager then all your files under ROOT/DEMO will not be accessible.

    Author Comment

    Thanks for the information.

    The reason I am asking this is because I want to set up a DEMO site, which has exact same thing ROOT has.
    I try to make the DEMO site runs on its own.
    But the problem is it seems to target back to ROOT website after serverlet did its work.

    maybe it's because the servlet mapping issue,
    I have

    it looks like when I call "/login", it's actually using ROOT's servlet, and then target back to ROOT's page.

    Any advice?
    LVL 8

    Expert Comment

    where have you put your DEMO folder and what do you have in your LoginServlet??

    Author Comment

    I have this in my login.jsp page:
    <form action="/login">

    Will this call the loginServlet in ROOT? or in DEMO?

    also I have a response.sendRedirect() in the loginServlet.
    which do sendRedirect("/index.jsp")

    It seems to redirct to ROOT/index.jsp rather than DEMO/index.jsp

    I don't know which part is giving me problem
    LVL 8

    Expert Comment

    ok, if you have a servlet mapping for /login to LoginServlet then when your form in login.jsp is submitted it will call the LoginServlet.
    This as i explained above is in the web.xml which can only be in ROOT-->WEB-INF folder.

    you can post your web.xml here and also the Directory contents of ROOT

    Author Comment

    I have this in my server.xml
    <Context path="" docBase="ROOT" debug="0" />
    <Context path="/DEMO" docBase="DEMO" debug="0" />

    There are no DEMO under ROOT.
    DEMO folder is at same level as ROOT

    I have /webApp/ROOT/, and /webApp/DEMO/

    I can load, and enter login info,
    but after login succeed, the page will be redirected to
    But I expect it to be

    This is what happened...........

    Thank you again.
    LVL 8

    Accepted Solution

    ok, try this
    response.sendRedirect("index.jsp")  (no leading /  )



    in your LoginServlet

    LVL 8

    Expert Comment

    I feel if the option has been tried out then it would have solved the problem...
    so i deserve to get the points!!!!! :)

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Suggested Solutions

    As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
    In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
    Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now