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

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.
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

>>> 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.
tsongweiAuthor Commented:
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?
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

where have you put your DEMO folder and what do you have in your LoginServlet??
tsongweiAuthor Commented:
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
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
tsongweiAuthor Commented:
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 www.mysite.com/DEMO/login.jsp, and enter login info,
but after login succeed, the page will be redirected to www.mysite.com/index.jsp
But I expect it to be www.mysite.com/DEMO/index.jsp

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

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



in your LoginServlet


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
I feel if the option has been tried out then it would have solved the problem...
so i deserve to get the points!!!!! :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.