11

Ive been learning Spring, JSP and servlets. I don't understand the concept of a context root. There are so many of them. SpringContext root, servlet context root and there may be others.

In a Spring MVC application, how many context roots are there and how to identify them? What do they really mean?

6
  • 1
    You may want to start small with writing a simple servlets application first. You need to understand that world thoroughly - all the rest is built on that. Commented Nov 12, 2013 at 22:05
  • 1
    This question cannot be given a concise answer that fits within the SO guidelines. It really requires a tutorial on servlets, which is available elsewhere. I second @ThorbjørnRavnAndersen: go through the servlets tutorial on Oracle's Java website. Commented Nov 12, 2013 at 22:40
  • 1
    Its surprising that there is that much prereq knowledge required to learn a framework. I dont see why creating a servlets application is important for the question i asked. I already know the role of a dispatcher servlet, front controller. IOC i understand thoroughly. Cant someone explain conceptually what is meant by a context root. Im sure ill understand. Try explaining Commented Nov 12, 2013 at 22:44
  • @ThorbjørnRavnAndersen is right. As an answer to your Spring MVC related question, I hope my following answer will shed at least some light (start reading from the section "Long Answer"): Spring: namespace vs contextConfigLocation init parameters in web.xml. And as was already recommended by others, read some basic tutorials first, like the popular: Beginning & Intermediate Servlet & JSP Tutorials Commented Nov 12, 2013 at 23:26
  • 1
    How can you understand a dispatcher servlet thoroughly if you do not understand context roots? Commented Nov 13, 2013 at 4:39

1 Answer 1

8

A context usually refers to the interface used to interact with your runtime environment. This one provides to your program a set of features (like security, request handling, etc...) usually needed by all application running in this kind of domain. Such an environment is generally named container in the java stack (servlet container, ejb one, etc...)

See What exactly is a Context in Java?

The term root can then be used when there are different context set up for a single application with inheritance between them. The one at the root hierarchy (usually holding some general configuration) is the root context .

See JB Nizet answer here : Web-application context/ root application context and transaction manager setup

However in your case the term root has a peculiar signification as it's used for a web container. It refers mainly to the root of the web application path, as there is only one context per web-app we are talking about the context root of a given web-app.

See http://tomcat.apache.org/tomcat-7.0-doc/config/context.html

Not the answer you're looking for? Browse other questions tagged or ask your own question.