permaculture playing cards
The moose likes Other Application Frameworks and the fly likes I wonder how servlet works Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "I wonder how servlet works" Watch "I wonder how servlet works" New topic

I wonder how servlet works

thomas jacob
Ranch Hand

Joined: May 19, 2005
Posts: 91
1)I have a web.xml with this content



2) I have a file

public class SpringappController implements Controller {
/** Logger for this class and subclasses */
protected final Log logger = LogFactory.getLog("SpringappController.class");

private ProductManager prodMan;

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String now = (new Date()).toString();"SpringappController - returning hello view"+now);
Map myModel = new HashMap();
myModel.put("now", now);
myModel.put("products", getProductManager().getProducts());

return new ModelAndView("hello", "model", myModel);

public void setProductManager(ProductManager pm) {
prodMan = pm;

public ProductManager getProductManager() {
return prodMan;


My Doubt: In the web.xml <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> is called to handle requests, but indirectly the SpringappController class handles the requests.
How does the servlet container know that SpringappController is the DispatcherServlet?.
Bear Bibeault
Author and ninkuma

Joined: Jan 10, 2002
Posts: 63837

Since this seems to be more about Spring than servlets, moved to the frameworks forum.

[Asking smart questions] [About Bear] [Books by Bear]
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

DispatcherServlet will look for another xml file called [servletname]-servlet.xml (i.e. springapp-servlet.xml)

Look into this file, and you'll propably see some handler mappings, like BeanNameUrlHandlerMapping or SimpleUrlHandlerMapping.
These handlers are responsible for mapping requests to servlets.

[My Blog]
All roads lead to JavaRanch
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15302

And then look in this file for that and that file for this. And don't forget to map this to that and make sure you have specified the mapping in the correct map or the mapping won't map to the map correctly.

Sorry, couldn't resist. Back to your regularly scheduled coding...

GenRocket - Experts at Building Test Data
Christophe Verré

Joined: Nov 24, 2005
Posts: 14688

You'll get banned from the frameworks forum
I agree. Here's the link:
subject: I wonder how servlet works
It's not a secret anymore!