0
Sponsored Links


Ad by Google
The topic is about front controller in Spring MVC not about the front controller design pattern although front controller in spring is the implementation of front controller design pattern, but here we are not going to dig into the deep of front controller design pattern. We are going to see what is front controller in Spring MVC.

Front-Controller: Is a initial level of contract point for handling a request. The front controller provides a centralized entry point for that controls and manages web request handling. By centralizing decision point and controls.

The front controller also reduce your java code and business logic by promoting code reuse ability across the requests. The front controller coordinates with dispatcher components. Dispatcher are responsible to view management only, the one who bring the view components to the user is called dispatcher.
There are lot of things about the front controller design pattern but we are not going here into the deep, we will see about front controller design pattern in detail in another post.

In Spring MVC org.springframework.web.servlet.DispatcherServlet is a front controller who handles all the user request and process the request as per there mapping.

For Example suppose you are going for an interview with reputed company once you entered inside the premisses, you will not directly entered in interview panel, someone who will process your CV and bring you to the front of interview panel. Each and every candidate first reached on common place and few HR person were there who took your CV and bring you to the front of interviewer. Here HR persons are the front controller who process each and every request and based your experience level they will send to the interviewer for the same.

Here is the example of defining front controler in web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>Spring4_MVC_Hello_World_Example</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
   </welcome-file-list>
  
  <servlet>
  <!-- spring4demo servlet name can be anything -->
  <servlet-name>spring4demo</servlet-name>    
   <!-- DispatcherServlet Known as front controller in spring -->
  <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
  <load-on-startup>1</load-on-startup>    
 </servlet>    
 <servlet-mapping>    
  <servlet-name>spring4demo</servlet-name>    
  <url-pattern>*.htm</url-pattern>    
 </servlet-mapping>  
</web-app>


References:
http://www.oracle.com/technetwork/java/frontcontroller-135648.html
Sponsored Links

0 comments:

Post a Comment