{"id":48981,"date":"2017-08-17T15:00:39","date_gmt":"2017-08-17T12:00:39","guid":{"rendered":"http:\/\/examples.javacodegeeks.com\/?p=48981"},"modified":"2019-02-25T13:18:03","modified_gmt":"2019-02-25T11:18:03","slug":"spring-mvc-3-0-tutorial","status":"publish","type":"post","link":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/","title":{"rendered":"Spring MVC 3.0 Tutorial"},"content":{"rendered":"<p>Spring MVC (Model-View-Controller) is the web component of Spring framework, which provides a great functionality for building web Applications. Following the basic tenet of Spring framework &#8220;<strong>convention over configuration<\/strong>&#8220;, the Spring MVC Framework is designed in such a way that every piece of logic and functionality is highly configurable. Spring is not tightly coupled with Servlet or JSP technology paradigms to render the view to the clients. It is also very simple and easy to integrate Spring with other Web Frameworks. Thus Spring is a perfect and logical choice for building multi-faceted web application with multiple interfaces. Additionally, Spring MVC can also work seamlessly with third party view technologies like Velocity, Freemarker and document manipulation APIs like Apace POI, Aspose etc.\n<\/p>\n<div class=\"toc\">\n<h3>Table Of Contents<\/h3>\n<dl>\n<dt><a href=\"#introduction\">1. Introduction<\/a><\/dt>\n<dt><a href=\"#tech\">2. Technologies used<\/a><\/dt>\n<dt><a href=\"#setMaven\">3. Setup Maven project<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#setMaven_sub\">3.1. Create maven project in Spring Tool Suite<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#demo\">4. Project Demo<\/a><\/dt>\n<dd>\n<dl>\n<dt><a href=\"#demo_appconfig\">4.1. Setting up application configuration<\/a><\/dt>\n<dt><a href=\"#demo_springconfig\">4.2. Setting up the Spring configuration<\/a><\/dt>\n<dt><a href=\"#demo_controller\">4.3. Setting up the Controller<\/a><\/dt>\n<dt><a href=\"#demo_jsp\">4.4. Setting up the JSP page<\/a><\/dt>\n<dt><a href=\"#demo_view\">4.5. View in browser<\/a><\/dt>\n<\/dl>\n<\/dd>\n<dt><a href=\"#conclusion\">5. Conclusion<\/a><\/dt>\n<dt><a href=\"#references\">6. References<\/a><\/dt>\n<dt><a href=\"#sourcecode\">7. Download Source Code<\/a><\/dt>\n<\/dl>\n<\/div>\n<h2><a name=\"introduction\"><\/a>1. Spring MVC Tutorial &#8211; Introduction<\/h2>\n<p>MVC stands for Model-View-Controller. Like most other MVC frameworks, Spring MVC is also request-driven. The Spring Web model-view-controller (MVC) framework is designed around a\u00a0<code>DispatcherServlet<\/code>\u00a0that dispatches requests to handlers, with configurable handler mappings, view resolution, locale, time zone and theme resolution as well as support for uploading files. The <code>DispatcherServlet<\/code> is completely integrated with Spring IoC container. The default handler is based on the\u00a0<code>@Controller<\/code>\u00a0and\u00a0<code>@RequestMapping<\/code>\u00a0annotations, offering a wide range of flexible handling methods.<\/p>\n<p><figure id=\"attachment_49317\" aria-describedby=\"caption-attachment-49317\" style=\"width: 390px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/spring_mvc_architecture.jpg\"><img decoding=\"async\" class=\"wp-image-49317 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/spring_mvc_architecture.jpg\" alt=\"Spring MVC Tutorial - Spring MVC architecture\" width=\"390\" height=\"273\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/spring_mvc_architecture.jpg 390w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/spring_mvc_architecture-300x210.jpg 300w\" sizes=\"(max-width: 390px) 100vw, 390px\" \/><\/a><figcaption id=\"caption-attachment-49317\" class=\"wp-caption-text\">Fig. 1 Spring MVC architecture<\/figcaption><\/figure><\/p>\n<p>The request processing flow in Spring MVC is as follows:<\/p>\n<ul>\n<li>A request is sent from the client to the web container as a http request.<\/li>\n<li>This request is first intercepted by the <code>DispatcherServlet<\/code>,which then looks for appropriate handler mappings designated to handle that request.<\/li>\n<li>The handler mappings contain a list of controllers. <code>DispatcherServlet<\/code> will forward the request to the correct controller.<\/li>\n<li>The controller will process the request and send back the backing model and view object to the <code>DispatcherServlet<\/code>.<br \/>\nThe <code>DispatcherServlet<\/code> will then resolve the view with the help of <code>ViewResolver<\/code> mappings. This is consulted to resolve views which can be JSP, Velocity etc.<\/li>\n<li>The final view is sent to the client and rendered on browser.<\/li>\n<\/ul>\n<p><figure id=\"attachment_49318\" aria-describedby=\"caption-attachment-49318\" style=\"width: 473px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/request_process_lifecycle.jpg\"><img decoding=\"async\" class=\"wp-image-49318 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/request_process_lifecycle.jpg\" alt=\"Spring MVC Tutorial -  Request Process Lifecycle\" width=\"473\" height=\"296\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/request_process_lifecycle.jpg 473w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/request_process_lifecycle-300x188.jpg 300w\" sizes=\"(max-width: 473px) 100vw, 473px\" \/><\/a><figcaption id=\"caption-attachment-49318\" class=\"wp-caption-text\">Fig. 2 Request Process Lifecycle<\/figcaption><\/figure><\/p>\n<h2><a name=\"tech\"><\/a>2. Technologies used<\/h2>\n<ol>\n<li>Spring 4.2.6.RELEASE<\/li>\n<li>Maven 3<\/li>\n<li>JDK 1.8<\/li>\n<li>Spring Tool Suite (STS) 3.9.0<\/li>\n<li>Java Server Pages<\/li>\n<\/ol>\n<h2><a name=\"setMaven\"><\/a>3. Setup Maven project<\/h2>\n<p>In this tutorial, we show you a Spring MVC hello world example, using Maven build tool.<br \/>\n<strong>Maven dependencies:<\/strong> We will be using Apache Maven for our project management. The required dependencies for a Spring MVC project are added and Maven will resolve and manage all the dependencies automatically. Below is the\u00a0<code>pom.xml<\/code>\u00a0file for our project.<\/p>\n<p><figure id=\"attachment_49311\" aria-describedby=\"caption-attachment-49311\" style=\"width: 529px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/pomFile.jpg\"><img decoding=\"async\" class=\"wp-image-49311 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/pomFile.jpg\" alt=\"Spring MVC Tutorial - POM file\" width=\"529\" height=\"690\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/pomFile.jpg 529w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/pomFile-230x300.jpg 230w\" sizes=\"(max-width: 529px) 100vw, 529px\" \/><\/a><figcaption id=\"caption-attachment-49311\" class=\"wp-caption-text\">Fig. 3 POM file<\/figcaption><\/figure><\/p>\n<p>We have included the\u00a0<code>maven-war-plugin<\/code> since we are configuring our application using Java Configuration, we don\u2019t need the\u00a0<code>web.xml<\/code>\u00a0anymore. In order for our project to build successfully, we need to instruct Maven to ignore the web.xml file. We do this by setting the\u00a0<code>failOnMissingWebXml<\/code>\u00a0element to false.<\/p>\n<h3><a name=\"setMaven_sub\"><\/a>3.1 Create a Maven Project in Spring Tool Suite<\/h3>\n<ul>\n<li>Navigate to File menu in Eclipse or Spring Tool Suite IDE.<\/li>\n<li>Click \u2018File\u2019 -&gt; \u2018New\u2019 -&gt; \u2018Maven Project\u2019.<\/li>\n<\/ul>\n<p><figure id=\"attachment_49307\" aria-describedby=\"caption-attachment-49307\" style=\"width: 525px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn1.jpg\"><img decoding=\"async\" class=\"wp-image-49307 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn1.jpg\" alt=\"Spring MVC Tutorial - Maven project\" width=\"525\" height=\"500\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn1.jpg 525w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn1-300x286.jpg 300w\" sizes=\"(max-width: 525px) 100vw, 525px\" \/><\/a><figcaption id=\"caption-attachment-49307\" class=\"wp-caption-text\">Fig. 4 Create Maven project<\/figcaption><\/figure><\/p>\n<p>Under the \u201cNew Maven Project\u201d window:<\/p>\n<ul>\n<li>Select \u2018Create a simple project\u2026.\u2019 check box.<\/li>\n<li>The remaining options can be kept as it is and simply click on \u2018Next\u2019.<\/li>\n<\/ul>\n<p><figure id=\"attachment_49308\" aria-describedby=\"caption-attachment-49308\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn2.jpg\"><img decoding=\"async\" class=\"wp-image-49308 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn2.jpg\" alt=\"\" width=\"800\" height=\"590\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn2.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn2-300x221.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn2-768x566.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-49308\" class=\"wp-caption-text\">Fig. 5 Create Maven 2<\/figcaption><\/figure><\/p>\n<p>In the next window enter the following options:<\/p>\n<ul>\n<li>For\u00a0<code>Group ID<\/code>\u00a0enter\u00a0<em>com.springmvccodegeeks<\/em><\/li>\n<li>For\u00a0<code>Artifact ID<\/code>\u00a0enter <em>springmvccodegeeks<\/em><\/li>\n<li>The remaining options can be kept as it is (We will be working with a jar file here)<\/li>\n<li>Click on \u2018Finish\u2019.<\/li>\n<\/ul>\n<p><figure id=\"attachment_49309\" aria-describedby=\"caption-attachment-49309\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn3.jpg\"><img decoding=\"async\" class=\"wp-image-49309 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn3.jpg\" alt=\"\" width=\"800\" height=\"590\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn3.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn3-300x221.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn3-768x566.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-49309\" class=\"wp-caption-text\">Fig. 6 Create project attributes<\/figcaption><\/figure><\/p>\n<p>A new maven project is created and is visible under Package Explorer in Eclipse<\/p>\n<p><figure id=\"attachment_49310\" aria-describedby=\"caption-attachment-49310\" style=\"width: 264px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn4FinalProjStruc.jpg\"><img decoding=\"async\" class=\"wp-image-49310 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/createMvn4FinalProjStruc.jpg\" alt=\"\" width=\"264\" height=\"165\" \/><\/a><figcaption id=\"caption-attachment-49310\" class=\"wp-caption-text\">Fig. 5 Final maven project structure<\/figcaption><\/figure><div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<h2><a name=\"demo\"><\/a>4. Project Demo<\/h2>\n<h3><a name=\"demo_appconfig\"><\/a>4.1 Setting up application configuration<\/h3>\n<p>In this example we are using java based configurations. These style of configurations allow for more flexibility and easier debugging capabilities. Hence we will not be using the traditional web.xml. Instead we will be implementing the <code>org.springframework.web.WebApplicationInitializer<\/code> API to spin up our application context.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SpringMvcInitializer.java<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_119372\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<div class=\"line number15 index14 alt2\">15<\/div>\n<div class=\"line number16 index15 alt1\">16<\/div>\n<div class=\"line number17 index16 alt2\">17<\/div>\n<div class=\"line number18 index17 alt1\">18<\/div>\n<div class=\"line number19 index18 alt2\">19<\/div>\n<div class=\"line number20 index19 alt1\">20<\/div>\n<div class=\"line number21 index20 alt2\">21<\/div>\n<div class=\"line number22 index21 alt1\">22<\/div>\n<div class=\"line number23 index22 alt2\">23<\/div>\n<div class=\"line number24 index23 alt1\">24<\/div>\n<div class=\"line number25 index24 alt2\">25<\/div>\n<div class=\"line number26 index25 alt1\">26<\/div>\n<div class=\"line number27 index26 alt2\">27<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">class<\/code> <code class=\"java plain\">SpringMvcInitializer <\/code><code class=\"java keyword\">extends<\/code> <code class=\"java plain\">AbstractAnnotationConfigDispatcherServletInitializer {<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">\/* (non-Javadoc)<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">* @see org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer#getRootConfigClasses()<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">*\/<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java color1\">@Override<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">protected<\/code> <code class=\"java plain\">Class&lt;?&gt;[] getRootConfigClasses() {<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">return<\/code> <code class=\"java keyword\">new<\/code> <code class=\"java plain\">Class[] { SpringMvcConfig.<\/code><code class=\"java keyword\">class<\/code> <code class=\"java plain\">};<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">\/* (non-Javadoc)<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">* @see org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer#getServletConfigClasses()<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">*\/<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java color1\">@Override<\/code><\/div>\n<div class=\"line number15 index14 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">protected<\/code> <code class=\"java plain\">Class&lt;?&gt;[] getServletConfigClasses() {\u00a0\u00a0\u00a0\u00a0\u00a0 <\/code><\/div>\n<div class=\"line number16 index15 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">return<\/code> <code class=\"java keyword\">null<\/code><code class=\"java plain\">;<\/code><\/div>\n<div class=\"line number17 index16 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number18 index17 alt1\"><\/div>\n<div class=\"line number19 index18 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">\/* (non-Javadoc)<\/code><\/div>\n<div class=\"line number20 index19 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">* @see org.springframework.web.servlet.support.AbstractDispatcherServletInitializer#getServletMappings()<\/code><\/div>\n<div class=\"line number21 index20 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java comments\">*\/<\/code><\/div>\n<div class=\"line number22 index21 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java color1\">@Override<\/code><\/div>\n<div class=\"line number23 index22 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">protected<\/code> <code class=\"java plain\">String[] getServletMappings() {<\/code><\/div>\n<div class=\"line number24 index23 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">return<\/code> <code class=\"java keyword\">new<\/code> <code class=\"java plain\">String[] { <\/code><code class=\"java string\">\"\/\"<\/code> <code class=\"java plain\">};<\/code><\/div>\n<div class=\"line number25 index24 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number26 index25 alt1\"><\/div>\n<div class=\"line number27 index26 alt2\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>Here the method <code>getRootConfigClasses()<\/code> should return a class setting up the application root context. The method <code>getServletConfigClasses()<\/code> should return a class setting up the web context on top of the previously defined application context. In our example, however, to keep things simple, the root context class itself is setting up the necessary contexts. Finally, <code>getServletMappings<\/code> defines the http API endpoints to be responded by the <code>DispatcherServlet<\/code>. This can be modified to hold different string patterns.<\/p>\n<h3><a name=\"demo_springconfig\"><\/a>4.2 Setting up the Spring configuration<\/h3>\n<p>Since we have moved away from xml-based configurations, we are creating the spring application context in java class. To setup the spring MVC configs, this java config class should extend the <code>org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter<\/code>\u00a0class.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>SpringMvcConfig.java<\/em><\/span>[ulp id=&#8217;7POIYxRf1FUtPpmL&#8217;]<\/p>\n<div>\n<div id=\"highlighter_345504\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">01<\/div>\n<div class=\"line number2 index1 alt1\">02<\/div>\n<div class=\"line number3 index2 alt2\">03<\/div>\n<div class=\"line number4 index3 alt1\">04<\/div>\n<div class=\"line number5 index4 alt2\">05<\/div>\n<div class=\"line number6 index5 alt1\">06<\/div>\n<div class=\"line number7 index6 alt2\">07<\/div>\n<div class=\"line number8 index7 alt1\">08<\/div>\n<div class=\"line number9 index8 alt2\">09<\/div>\n<div class=\"line number10 index9 alt1\">10<\/div>\n<div class=\"line number11 index10 alt2\">11<\/div>\n<div class=\"line number12 index11 alt1\">12<\/div>\n<div class=\"line number13 index12 alt2\">13<\/div>\n<div class=\"line number14 index13 alt1\">14<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java color1\">@Configuration<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java color1\">@EnableWebMvc<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><code class=\"java color1\">@ComponentScan<\/code><code class=\"java plain\">(basePackages = {<\/code><code class=\"java string\">\"com.springmvccodegeeks\"<\/code><code class=\"java plain\">})<\/code><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">class<\/code> <code class=\"java plain\">SpringMvcConfig <\/code><code class=\"java keyword\">extends<\/code> <code class=\"java plain\">WebMvcConfigurerAdapter {<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java color1\">@Bean<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">public<\/code> <code class=\"java plain\">ViewResolver viewResolver() {<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">InternalResourceViewResolver viewResolver = <\/code><code class=\"java keyword\">new<\/code> <code class=\"java plain\">InternalResourceViewResolver();<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">viewResolver.setViewClass(JstlView.<\/code><code class=\"java keyword\">class<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number10 index9 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">viewResolver.setPrefix(<\/code><code class=\"java string\">\"\/WEB-INF\/views\/\"<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number11 index10 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">viewResolver.setSuffix(<\/code><code class=\"java string\">\".jsp\"<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number12 index11 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">return<\/code> <code class=\"java plain\">viewResolver;<\/code><\/div>\n<div class=\"line number13 index12 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number14 index13 alt1\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<p>The uses for the different annotations:<br \/>\n<code>@Configuration<\/code> &#8211; This annotation will tell spring application context to treat this as a configuration class during auto scanning.<br \/>\n<code>@EnableWebMvc<\/code> &#8211; Enable Spring MVC-specific annotations like <code>@Controller<\/code><br \/>\n<code>@ComponentScan<\/code> &#8211; Scan starts from base package and registers all controllers, repositories, service, beans, etc. Include the packages here which contains beans or classes for the application to inject when required.<br \/>\n<code>@Bean<\/code> &#8211; Defines spring beans. Here we have defined the <code>ViewResolver<\/code><\/p>\n<h3><a name=\"demo_controller\"><\/a>4.3 Setting up the Controller<\/h3>\n<p>We are annotating the class with <code>@Controller<\/code> annotation. This annotation is a stereo type annotation used to indicate that this is a controller. This enables the <code>DispatcherServlet<\/code> to automatically map the methods defined in the class using the <code>@RequestMapping<\/code> annotation.<\/p>\n<p>The <code>@RequestMapping<\/code> annotation maps the URL\u2019s onto particular classes or methods. The class-level annotation is mostly used to map a specific request path onto a form controller, whereas a method-level annotations narrows the mapping for a specific HTTP request method like (GET, PUT, POST and DELETE). In this example, we are using the annotation at the method level. Also, we are populating the Model map. This is a map for the request attributes. It contains a key called message and a simple string value.<\/p>\n<p>The return value is the name of the view. The <code>InternalResourceViewResolver<\/code> will prefix and suffix the return value to form the real path of the view file name.<\/p>\n<p><span style=\"text-decoration: underline;\"><em>DefaultController.java<\/em><\/span><\/p>\n<div>\n<div id=\"highlighter_677378\" class=\"syntaxhighlighter  java\">\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<td class=\"gutter\">\n<div class=\"line number1 index0 alt2\">1<\/div>\n<div class=\"line number2 index1 alt1\">2<\/div>\n<div class=\"line number3 index2 alt2\">3<\/div>\n<div class=\"line number4 index3 alt1\">4<\/div>\n<div class=\"line number5 index4 alt2\">5<\/div>\n<div class=\"line number6 index5 alt1\">6<\/div>\n<div class=\"line number7 index6 alt2\">7<\/div>\n<div class=\"line number8 index7 alt1\">8<\/div>\n<div class=\"line number9 index8 alt2\">9<\/div>\n<\/td>\n<td class=\"code\">\n<div class=\"container\">\n<div class=\"line number1 index0 alt2\"><code class=\"java color1\">@Controller<\/code><\/div>\n<div class=\"line number2 index1 alt1\"><code class=\"java keyword\">public<\/code> <code class=\"java keyword\">class<\/code> <code class=\"java plain\">DefaultController {<\/code><\/div>\n<div class=\"line number3 index2 alt2\"><\/div>\n<div class=\"line number4 index3 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java color1\">@RequestMapping<\/code><code class=\"java plain\">(value = <\/code><code class=\"java string\">\"\/\"<\/code><code class=\"java plain\">, method = RequestMethod.GET)<\/code><\/div>\n<div class=\"line number5 index4 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">public<\/code> <code class=\"java plain\">String index(ModelMap model) {<\/code><\/div>\n<div class=\"line number6 index5 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">model.addAttribute(<\/code><code class=\"java string\">\"message\"<\/code><code class=\"java plain\">, <\/code><code class=\"java string\">\"Spring MVC Java Configuration Example!!\"<\/code><code class=\"java plain\">);<\/code><\/div>\n<div class=\"line number7 index6 alt2\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java keyword\">return<\/code> <code class=\"java string\">\"index\"<\/code><code class=\"java plain\">;<\/code><\/div>\n<div class=\"line number8 index7 alt1\"><code class=\"java spaces\">\u00a0\u00a0\u00a0\u00a0<\/code><code class=\"java plain\">}<\/code><\/div>\n<div class=\"line number9 index8 alt2\"><code class=\"java plain\">}<\/code><\/div>\n<\/div>\n<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n<\/div>\n<h3><a name=\"demo_jsp\"><\/a>4.4 Setting up the JSP page<\/h3>\n<p>We are creating a simple JSP page here. This page will be rendered as the home page when the main application endpoint is requested from a client (browser). This view will display the value of the message attribute we added earlier in the controller.<\/p>\n<p><figure id=\"attachment_49313\" aria-describedby=\"caption-attachment-49313\" style=\"width: 543px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/indexFile.jpg\"><img decoding=\"async\" class=\"wp-image-49313 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/indexFile.jpg\" alt=\"\" width=\"543\" height=\"195\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/indexFile.jpg 543w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/indexFile-300x108.jpg 300w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><\/a><figcaption id=\"caption-attachment-49313\" class=\"wp-caption-text\">Fig. 7 index.jsp<\/figcaption><\/figure><\/p>\n<p>The final project structure is as below:<\/p>\n<p><figure id=\"attachment_49314\" aria-describedby=\"caption-attachment-49314\" style=\"width: 325px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/finalPrjStr.jpg\"><img decoding=\"async\" class=\"wp-image-49314 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/finalPrjStr.jpg\" alt=\"\" width=\"325\" height=\"398\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/finalPrjStr.jpg 325w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/finalPrjStr-245x300.jpg 245w\" sizes=\"(max-width: 325px) 100vw, 325px\" \/><\/a><figcaption id=\"caption-attachment-49314\" class=\"wp-caption-text\">Fig. 8 Final project structure<\/figcaption><\/figure><\/p>\n<h3><a name=\"demo_view\"><\/a>4.5 View in browser<\/h3>\n<p>Start the embedded application server that comes with the IDE. Open a browser and enter the URL: <code>http:\/\/localhost:8080\/springmvccodegeeks\/<\/code> . The message <em>&#8220;Spring MVC Java Configuration Example!!&#8221;<\/em> is displayed as was defined in the controller method. This is a simple view rendering.<\/p>\n<p><figure id=\"attachment_49315\" aria-describedby=\"caption-attachment-49315\" style=\"width: 800px\" class=\"wp-caption aligncenter\"><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/ViewBrowser.jpg\"><img decoding=\"async\" class=\"wp-image-49315 size-full\" src=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/ViewBrowser.jpg\" alt=\"\" width=\"800\" height=\"366\" srcset=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/ViewBrowser.jpg 800w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/ViewBrowser-300x137.jpg 300w, https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/ViewBrowser-768x351.jpg 768w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><figcaption id=\"caption-attachment-49315\" class=\"wp-caption-text\">Fig. 9 View application in browser<\/figcaption><\/figure><\/p>\n<h2><a name=\"#conclusion\"><\/a>5. Conclusion<\/h2>\n<p>In this example we have covered the following:<\/p>\n<ul>\n<li>Understand the basic concepts and main elements of a Spring MVC project<\/li>\n<li>Setup a simple MVC project using maven<\/li>\n<li>Render a page and display customized message using spring MVC<\/li>\n<\/ul>\n<h2><a name=\"#references\"><\/a>6. References<\/h2>\n<ul>\n<li><a href=\"https:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/mvc.html\">https:\/\/docs.spring.io\/spring\/docs\/current\/spring-framework-reference\/html\/mvc.html<\/a><\/li>\n<li>Spring in Practice by Willie Wheeler et al<\/li>\n<li>Spring in Action by Craig Walls<\/li>\n<\/ul>\n<h2><a name=\"#sourcecode\"><\/a>7. Download the Source Code<\/h2>\n<div class=\"download\"><strong>Download<\/strong><br \/>\nYou can download the full source code of this example here: <strong><a href=\"http:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/08\/SpringMVC.zip\">SpringMVC<\/a><\/strong><\/div>\n","protected":false},"excerpt":{"rendered":"<p>Spring MVC (Model-View-Controller) is the web component of Spring framework, which provides a great functionality for building web Applications. Following the basic tenet of Spring framework &#8220;convention over configuration&#8220;, the Spring MVC Framework is designed in such a way that every piece of logic and functionality is highly configurable. Spring is not tightly coupled with &hellip;<\/p>\n","protected":false},"author":131,"featured_media":1248,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[52],"tags":[1054,1213],"class_list":["post-48981","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-spring","tag-spring","tag-spring-mvc"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v26.5 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Spring MVC 3.0 Tutorial - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Spring MVC 3.0 Tutorial - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!\" \/>\n<meta property=\"og:url\" content=\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\" \/>\n<meta property=\"og:site_name\" content=\"Examples Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2017-08-17T12:00:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-25T11:18:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Diptayan Datta\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Diptayan Datta\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\"},\"author\":{\"name\":\"Diptayan Datta\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/0d7ca3afbac2142da3ea3e6d3d5aa8b5\"},\"headline\":\"Spring MVC 3.0 Tutorial\",\"datePublished\":\"2017-08-17T12:00:39+00:00\",\"dateModified\":\"2019-02-25T11:18:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\"},\"wordCount\":1258,\"commentCount\":1,\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"keywords\":[\"spring\",\"Spring MVC\"],\"articleSection\":[\"spring\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\",\"name\":\"Spring MVC 3.0 Tutorial - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"datePublished\":\"2017-08-17T12:00:39+00:00\",\"dateModified\":\"2019-02-25T11:18:03+00:00\",\"description\":\"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!\",\"breadcrumb\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/examples.javacodegeeks.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java Development\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"spring\",\"item\":\"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/\"},{\"@type\":\"ListItem\",\"position\":5,\"name\":\"Spring MVC 3.0 Tutorial\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#website\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Examples and Code Snippets\",\"publisher\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\/\/examples.javacodegeeks.com\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/\"},\"sameAs\":[\"https:\/\/www.facebook.com\/javacodegeeks\",\"https:\/\/x.com\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/0d7ca3afbac2142da3ea3e6d3d5aa8b5\",\"name\":\"Diptayan Datta\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Diptayan-Datta_avatar_1493019155-96x96.jpg\",\"contentUrl\":\"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Diptayan-Datta_avatar_1493019155-96x96.jpg\",\"caption\":\"Diptayan Datta\"},\"description\":\"Diptayan has a bachelors degree in Electronics and Communication Engineering. He also holds a Master degree in Information Systems. In his professional career, he has worked with several organizations in both software tester and developer roles. He is currently involved as an application developer in the Tax, Accounting and Corporate Law sector where he is working with Java, Spring, Hibernate, Selenium, JavaScript and AngularJS.\",\"sameAs\":[\"https:\/\/examples.javacodegeeks.com\/\"],\"url\":\"https:\/\/examples.javacodegeeks.com\/author\/diptayan-datta\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Spring MVC 3.0 Tutorial - Java Code Geeks","description":"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/","og_locale":"en_US","og_type":"article","og_title":"Spring MVC 3.0 Tutorial - Java Code Geeks","og_description":"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!","og_url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/","og_site_name":"Examples Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2017-08-17T12:00:39+00:00","article_modified_time":"2019-02-25T11:18:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","type":"image\/jpeg"}],"author":"Diptayan Datta","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Diptayan Datta","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#article","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/"},"author":{"name":"Diptayan Datta","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/0d7ca3afbac2142da3ea3e6d3d5aa8b5"},"headline":"Spring MVC 3.0 Tutorial","datePublished":"2017-08-17T12:00:39+00:00","dateModified":"2019-02-25T11:18:03+00:00","mainEntityOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/"},"wordCount":1258,"commentCount":1,"publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","keywords":["spring","Spring MVC"],"articleSection":["spring"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/","url":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/","name":"Spring MVC 3.0 Tutorial - Java Code Geeks","isPartOf":{"@id":"https:\/\/examples.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage"},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage"},"thumbnailUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","datePublished":"2017-08-17T12:00:39+00:00","dateModified":"2019-02-25T11:18:03+00:00","description":"Interested to learn more about Spring MVC? Then check out our detailed tutorial on Spring MVC!","breadcrumb":{"@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#primaryimage","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2012\/12\/spring-logo.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/examples.javacodegeeks.com\/java-development\/enterprise-java\/spring\/spring-mvc-3-0-tutorial\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/examples.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java Development","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/"},{"@type":"ListItem","position":4,"name":"spring","item":"https:\/\/examples.javacodegeeks.com\/category\/java-development\/enterprise-java\/spring\/"},{"@type":"ListItem","position":5,"name":"Spring MVC 3.0 Tutorial"}]},{"@type":"WebSite","@id":"https:\/\/examples.javacodegeeks.com\/#website","url":"https:\/\/examples.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Examples and Code Snippets","publisher":{"@id":"https:\/\/examples.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/examples.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/examples.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/examples.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/0d7ca3afbac2142da3ea3e6d3d5aa8b5","name":"Diptayan Datta","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/examples.javacodegeeks.com\/#\/schema\/person\/image\/","url":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Diptayan-Datta_avatar_1493019155-96x96.jpg","contentUrl":"https:\/\/examples.javacodegeeks.com\/wp-content\/uploads\/2017\/04\/Diptayan-Datta_avatar_1493019155-96x96.jpg","caption":"Diptayan Datta"},"description":"Diptayan has a bachelors degree in Electronics and Communication Engineering. He also holds a Master degree in Information Systems. In his professional career, he has worked with several organizations in both software tester and developer roles. He is currently involved as an application developer in the Tax, Accounting and Corporate Law sector where he is working with Java, Spring, Hibernate, Selenium, JavaScript and AngularJS.","sameAs":["https:\/\/examples.javacodegeeks.com\/"],"url":"https:\/\/examples.javacodegeeks.com\/author\/diptayan-datta\/"}]}},"_links":{"self":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48981","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/users\/131"}],"replies":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=48981"}],"version-history":[{"count":0,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/48981\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media\/1248"}],"wp:attachment":[{"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=48981"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=48981"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/examples.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=48981"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}