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?

Smern
  • 18,746
  • 21
  • 72
  • 90
Horse Voice
  • 8,138
  • 15
  • 69
  • 120
  • 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. – Thorbjørn Ravn Andersen Nov 12 '13 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. – Jim Garrison Nov 12 '13 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 – Horse Voice Nov 12 '13 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](http://stackoverflow.com/a/15825207/814702). And as was already recommended by others, read some basic tutorials first, like the popular: [Beginning & Intermediate Servlet & JSP Tutorials](http://courses.coreservlets.com/Course-Materials/csajsp2.html) – informatik01 Nov 12 '13 at 23:26
  • 1
    How can you understand a dispatcher servlet thoroughly if you do not understand context roots? – Thorbjørn Ravn Andersen Nov 13 '13 at 04:39
  • Is it important? I'm a developer not a java programmer. Things should be more straight forward. – Horse Voice Nov 15 '13 at 18:06

1 Answers1

7

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

Community
  • 1
  • 1
Gab
  • 7,869
  • 4
  • 37
  • 68