[Last Call] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 190
  • Last Modified:

<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.
  • 6
  • 3
1 Solution
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?
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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

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

Upgrade your Question Security!

Add Premium security features to your question to ensure its privacy or anonymity. Learn more about your ability to control Question Security today.

  • 6
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now