Social Media
  • You are here:
  • Home »
  • Java »

parkrunPB – Spring 3 and Spring MVC – Part 1

Model-View-Controller(MVC) is a software pattern for user interfaces. It encourages clean design by separating out the three components of the Graphical User Interface (GUI) into three components – Model,
View and Controller


It consists of 3 components –

  • Controller – This is normally Front Controller, which delegates to specific controls
  • Model – The controller updates the model
  • View – The controller then decides which view to return

The flow is sometimes easier to see in a sequence diagram –



Front Controller – web.xml

This is the starting point for configuration –


Here the DispatcherServlet is the Front Controller

Spring Configuration – spring-servlet.xml

This configuration is using the default name for the spring configuration file which matches the servlet name with a -servlet.xml appended – spring-servlet.xml

The key areas of this configuration are –

   <context:component-scan base-package="com.glenware.parkrunpb" />
   <context:annotation-config />

   <bean id="jspViewResolver"
      <property name="viewClass" value="org.springframework.web.servlet.view.JstlView" />
      <property name="prefix" value="/WEB-INF/jsp/" />
      <property name="suffix" value=".jsp" />

   <bean id="messageSource"
      <property name="basename" value="classpath:messages" />
      <property name="defaultEncoding" value="UTF-8" />

In spring terms we’re basically –

  • Setting up annotation driven configuration on package com.glenware.parkrunpb
  • ViewResolver – check /WEB-INF/jsp for files ending in .jsp
  • Messages – check classpath for

AboutController – Simple Example

The simplest controller in parkrunPB is the AboutController –

public class AboutController {

   public String about() {
      return "about";


 The key attributes of this controller are –

  • @Controller – Marks the class as a Controller
  • @RequestMapping(“/about”) – Method is called when /parkrunPB/about is called
  • return “about” – This is where the view resolver kicks in an searches for the corresponding view – /WEB-INF/jsp/about.jsp


Images courtesy of (any issues and they will be removed/replaced) –










About the Author Martin Farrell

My name is Martin Farrell. I have almost 20 years Java experience. I specialize inthe Spring Framework and JEE. I’ve consulted to a range of businesses, and have provide Java and Spring mentoring and training. You can learn more at About or on my consultancy website Glendevon Software

follow me on:

Leave a Comment: