<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<div dir="ltr" style="text-align: justify;">
<p><b> <i>What is Spring MVC Interceptor</i></b><i>? </i>In Web application when request comes to the controller , the <i><b>HandlerMapping </b></i>handler matches the incoming request. <i><b>DispatcherServlet </b></i>will hand it over to the handler mapping, to let it inspect the request and come up with an appropriate <i><b>HandlerExecutionChain</b></i>. Then the <b><i> DispatcherServlet </i></b>will execute the handler and interceptors in the chain. When it comes to interceptors you can perform the <b>your logic like logging, method tracking etc</b>. Lets see In below Request Flow Diagram of Spring3MVC framework as discuss in the earlier chapter.</p>
<div id="ads-id" align="center"></div>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Popular Tutorials</b></span></p>
<ul style="text-align: left;">
<li><b><a href="https://dineshonjava.com/spring-tutorial/"><em><strong>Spring Tutorial</strong> </em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><strong><em>Spring MVC Web Tutorial </em></strong></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-spring-boot-a-spring-boot-complete-guide/"><strong>Spring Boot Tutorial</strong> </a></b></li>
<li><b><a href="https://dineshonjava.com/spring-security-take-baby-step-to-secure/"><em>Spring Security Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-aop-tutorial-with-example-aspect-advice-pointcut-joinpoint/"><em>Spring AOP Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/using-spring-jdbc-framework-chapter-32/"><em>Spring JDBC Tutorial</em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-hateoas-hypermedia-driven-restful-web-service/"><em><strong>Spring HATEOAS </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/microservices-with-spring-boot/"><em><strong>Microservices with Spring Boot</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/jax-rs-web-service-tutorial/"><strong><em>REST Webservice</em> </strong></a></b></li>
<li><b><a href="https://dineshonjava.com/core-java-baby-step-to-be-best-java-ian/"><em><strong>Core Java </strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/hibernate-3-on-baby-steps/"><em><strong>Hibernate Tutorial</strong></em></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-batch-process-with-example/"><strong><em>Spring Batch</em> </strong></a></b></li>
</ul>
</div>
<p> ;</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2012/12/MVCDetail.jpg" width="640" height="460" border="0" /></div>
<p>As diagram we can see that <b>Spring3MVC Interceptor</b> framework intercepts an incoming <b>HTTP request</b> before it reaches your<b> Spring MVC controller</b> class, or conversely, intercepts the outgoing <b>HTTP response</b> after it leaves your controller, but before it’s fed back to the browser.<br />
<b><i><br />
</i></b> <b> <i>Why we use Spring3 MVC Interceptor</i></b><i>? </i><br />
<b><i>The answer is that it allows you to perform tasks that are common to every request or set of requests without the need to cut ‘n’ paste boiler plate code into every controller class.</i> </b>For example, you could perform user authentication of a request before it reaches your controller and, if successful, retrieve some additional user details from a database adding them to the <i><b>HttpServletRequest </b></i>object before your controller is called. Your controller can then simply retrieve and use these values or leave them for display by the JSP. On the other hand, if the authentication fails, you could re-direct your user to a different page.<br />
<i><b><br />
</b></i><br />
<i><b>Quick Overview of Spring Interceptor: </b></i><br />
Each interceptor you define must implement <i><b>org.springframework.web.servlet.HandlerInterceptor</b></i> interface. There are three methods that need to be implemented.</p>
<p><b><br />
</b> <b>1. </b><i><b>preHandle(..)</b> &#8212; </i>is called before the actual handler is executed.<br />
The <i><b>preHandle(..) </b></i>method returns a Boolean value. You can use this method to break or continue the processing of the execution chain. When this method returns true, the handler execution chain will continue; when it returns false, the <i><b>DispatcherServlet </b></i>assumes the interceptor itself has taken care of requests (and, for example, rendered an appropriate view) and does not continue executing the other interceptors and the actual handler in the execution chain.</p>
<p><b>2. <i>postHandle(..)</i> </b>&#8212; is called after the handler is executed.</p>
<p><b>3. </b><i><b>afterCompletion(..) &#8212; </b></i>is called after the complete request has finished.</p>
<p>These three methods should provide enough flexibility to do all kinds of <b>preprocessing and postprocessing</b>.</p>
</div>
<pre class="highlight">package com.dineshonjava.interceptor; 
 
import javax.servlet.http.HttpServletRequest; 
import javax.servlet.http.HttpServletResponse; 
 
import org.springframework.web.servlet.HandlerInterceptor; 
import org.springframework.web.servlet.ModelAndView; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
public class HelloWorldInterceptor implements HandlerInterceptor { 
 
 @Override 
 public void afterCompletion(HttpServletRequest request, 
 HttpServletResponse response, Object object, Exception exception) 
 throws Exception { 
 
 } 
 
 @Override 
 public void postHandle(HttpServletRequest request, HttpServletResponse response, 
 Object object, ModelAndView modelAndView) throws Exception { 
 
 } 
 
 @Override 
 public boolean preHandle(HttpServletRequest request, HttpServletResponse response, 
 Object object) throws Exception { 
 return false; 
 } 
} 
</pre>
<p>Once the interceptor is defined, you can ask Spring MVC to configure it via <i><b><;mvc:interceptors>;</b></i> tag within<i><b> sdnext-servlet.xml</b></i> file.</p>
<pre class="highlight"><;mvc:interceptors>; 
 <;bean class="com.dineshonjava.interceptor.HelloWorldInterceptor">;<;/bean>; 
<;/mvc:interceptors>; 
</pre>
<p>Let us start with the complete application for interceptor. We will create a <i><b>HelloWorldInterceptor </b></i>that logs and tracks each coming requests.</p>
<p>In this example show how to write a simple web based <b>Hello World</b> application using <b>Spring 3.0 MVC Interceptor </b>framework. To start with it, let us have working with <b>STS IDE</b> in place and follow the following steps to develop a <b>Dynamic Web Application</b> using <a style="color: #888888; text-decoration: initial;" href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38" target="_blank" rel="noopener"><b>Spring 3.0 Web MVC</b></a> Framework:<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step 1:</b> Create a <b><i>Dynamic Web Project</i></b> with a name <b><i>Spring3MVCInterceptorApp</i></b> and create two<i><b> </b></i>packages <i><b>com</b>.<b>dineshonjava.controller</b></i> and <i><b>com</b>.<b>dineshonjava.interceptor </b></i>under the <b><i>src</i> </b>folder in the created project.<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step 2: </b>Add below mentioned <b>Spring 3.0 libraries</b> and other libraries into the folder<b><i> WebRoot/WEB-INF/lib</i></b>. <br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" />/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/commons-fileupload-1.1.1.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/commons-io-1.2.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/commons-logging-1.1.1.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/hibernate-validator-4.0.2.GA.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/jstl-1.2.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/log4j-1.2.14.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/servlet-2.3.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/slf4j-api-1.5.6.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/slf4j-log4j12-1.5.6.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-asm-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-beans-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-context-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-core-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-expression-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-web-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/spring-webmvc-3.0.3.RELEASE.jar<br />
/SpringMVCHelloWorld/WebRoot/WEB-INF/lib/validation-api-1.0.0.GA.jar <br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step 3: </b>Create a Java class <b><i>HelloWorldController</i> </b>under the <i><b>com</b>.<b>dineshonjava.controller</b></i> package and another <b><i>HelloWorldInterceptor</i> </b>under the <i><b>com</b>.<b>dineshonjava.interceptor</b></i> package.<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step 4:</b> Create Spring configuration files <b><i>Web.xml</i></b> and <b><i>sdnext-servlet.xml</i></b> under the<i><b> </b></i><b><i>WebRoot/WEB-INF/ </i></b>folder.<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step 5:</b> Create a sub-folder with a name <i><b>views </b></i>under the <i><b>WebRoot/WEB-INF </b></i>folder. Create a view file <b><i>hello.jsp</i></b> under this sub-folder.<br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><br style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;" /><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Step <i>6</i>:</b> The final step is to create the content of all the source and configuration files name <i><b>sdnext-servlet.xml</b></i> under the sub-folder <i><b>WebRoot/WEB-INF/config </b></i>and export the application as explained below.</p>
<p><b style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">Software versions used to run the sample code:</b></p>
<ul style="-webkit-text-size-adjust: auto; -webkit-text-stroke-width: 0px; background-color: white; color: #222222; font-family: Arial, Tahoma, Helvetica, FreeSans, sans-serif; font-size: 13px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; line-height: 18px; margin: 0.5em 0px; orphans: 2; padding: 0px 2.5em; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;">
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Spring 3.0</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Java 1.6</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">Tomcat 7</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;">JSTL 1.2</li>
<li style="margin: 0px 0px 0.25em; padding: 0px; text-indent: 0px;"><b>STS</b> Java EE IDE</li>
</ul>
<p><b>Web Application Structure:</b></p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2012/12/interceptorMVC.jpg" border="0" /></div>
<p>Now we create the HelloWorldController file.</p>
<p><b>HelloWorldController.java</b></p>
<pre class="highlight">package com.dineshonjava.controller; 
 
import org.springframework.stereotype.Controller; 
import org.springframework.ui.ModelMap; 
import org.springframework.web.bind.annotation.RequestMapping; 
import org.springframework.web.bind.annotation.RequestMethod; 
 
/** 
 * @author Dinesh Rajput 
 * 
 */ 
@Controller 
@RequestMapping("/hello") 
public class HelloWorldController { 
 
 @RequestMapping(method = RequestMethod.GET) 
 public String sayHelloWorld(ModelMap model) { 
 model.addAttribute("message", "Spring 3.0 MVC Framework Hello World Example with Interceptor!"); 
 model.addAttribute("auther", "DineshOnJava"); 
 return "hello"; 
 } 
} 
</pre>
<p>The controller has one method <i><b>sayHelloWorld()</b></i> which is mapped to URL<i><b> /hello</b></i> using <i><b>@RequestMapping</b></i>. This simply paints the <i><b>hello.jsp</b></i> view.</p>
<p><i><b>hello.jsp</b></i></p>
<pre class="highlight"><;%@ page language="java" contentType="text/html; charset=ISO-8859-1" 
 pageEncoding="ISO-8859-1"%>; 
 
<;html>; 
 <;head>; 
 <;title>;Spring 3.0 MVC Hello World Example<;/title>; 
 <;/head>; 
 <;body>; 
 <;h2>; 
${message} <;/h2>; 
 <;h2>; 
${auther} <;/h2>; 
<;/body>; 
<;/html>; 
</pre>
<p><b><br />
</b> <b>Following is the content of Spring Web configuration file <i>web.xml</i></b></p>
<pre class="highlight"><;web-app id="WebApp_ID" version="3.0" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 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">; 
 
 <;display-name>;SpringMVCHelloWorld<;/display-name>; 
 <;welcome-file-list>; 
 <;welcome-file>;/<;/welcome-file>; 
 <;/welcome-file-list>; 
 
 <;servlet>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;servlet-class>; 
 org.springframework.web.servlet.DispatcherServlet 
 <;/servlet-class>; 
 <;init-param>; 
 <;param-name>;contextConfigLocation<;/param-name>;<;param-value>;/WEB-INF/config/sdnext-servlet.xml<;/param-value>;<;/init-param>; 
 <;load-on-startup>;1<;/load-on-startup>; 
 <;/servlet>; 
 <;servlet-mapping>; 
 <;servlet-name>;sdnext<;/servlet-name>; 
 <;url-pattern>;/<;/url-pattern>; 
 <;/servlet-mapping>; 
<;/web-app>; 
</pre>
<p><b><br />
</b> <b>Following is the content of another Spring Web configuration file <i>sdnext-servlet.xml</i></b></p>
<pre class="highlight"><;beans xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.springframework.org/schema/beans" xsi:schemalocation=" 
 http://www.springframework.org/schema/beans 
 http://www.springframework.org/schema/beans/spring-beans-3.0.xsd 
 http://www.springframework.org/schema/context 
 http://www.springframework.org/schema/context/spring-context-3.0.xsd 
 http://www.springframework.org/schema/mvc 
 http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">; 
 
<;!-- Enable annotation driven controllers, validation etc... -->; 
<;mvc:annotation-driven>;<;/mvc:annotation-driven>; 
 
<;context:component-scan base-package="com.dineshonjava.controller">; 
<;/context:component-scan>; 
 
<;bean class="org.springframework.web.servlet.view.InternalResourceViewResolver" id="viewResolver">; 
 <;property name="prefix" value="/WEB-INF/views/">;<;/property>; 
 <;property name="suffix" value=".jsp">;<;/property>; 
<;/bean>; 
 
<;mvc:interceptors>; 
 <;bean class="com.dineshonjava.interceptor.HelloWorldInterceptor">;<;/bean>; 
<;/mvc:interceptors>; 
 
<;/beans>; 
</pre>
<p>Once you are done with creating source and configuration files, export your application. Right click on your application and use <b><i>Export ->; WAR</i></b> File option and save your <i><b>Spring3MVCInterceptorApp.war</b></i> file in Tomcat&#8217;s web<b> </b>apps folder.</p>
<p>Now start your Tomcat server and make sure you are able to access other web pages from web apps folder using a standard browser. Now try to access the URL<b><i> http://localhost:8080/sdnext/hello </i></b>and if everything is fine with your Spring Web Application, you should see the following result:</p>
<p> ;</p>
<div class="separator" style="clear: both; text-align: center;"><img src="https://dineshonjava.com/wp-content/uploads/2012/12/interceptorMVCResult.jpg" width="640" height="206" border="0" /></div>
<p><b>Download Source Code</b><b>+Libs</b><br />
<b><a href="https://sites.google.com/site/dinesh9582486434/my-forms/Spring3MVCInterceptorApp.zip?attredirects=0&;d=1" target="_blank" rel="noopener">Spring<i>3</i>MVCInterceptorApp.zip</a> </b></p>
<p> ;</p>
<div style="background-color: #f2f9fc; border:1px solid #c9e6f2;border-radius:3px;padding:16px;line-height:1.45;">
<span style="color: red;font-size: x-large;text-align: center;"><b>Spring MVC Related Posts</b></span></p>
<ol style="text-align: left;"><span style="color: #274e13;"></p>
<li><b><a href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/"><span style="color: red;">Spring MVC Web Tutorial</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-interview-questions-and-answers/"><span style="color: red;">Spring MVC Interview Questions</span></a></b></li>
<li><b><a href="https://dineshonjava.com/introduction-to-mvc/"><span style="color: red;">MVC Design Pattern</span></a></b></li>
<li><b><a href="https://dineshonjava.com/what-is-dispatcherservlet-in-spring-and-its-uses/"><span style="color: red;">Spring MVC DispatcherServlet </span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC WebApplicationContext and Root Application Context</span></a></b></li>
<li><b><a href="https://dineshonjava.com/stereotype-annotations-in-spring/"><span style="color: red;">Spring MVC @Controller Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestmapping-annotation-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestMapping Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-annotation-in-spring-mvc-with-example/"><span style="color: red;">Spring MVC @RequestParam Annotation</span></a></b></li>
<li><b><a href="https://dineshonjava.com/difference-between-applicationcontext-webapplicationcontext-in-spring-mvc/"><span style="color: red;">Spring MVC ContextLoaderListener</span></a></b></li>
<li><b><a href="https://dineshonjava.com/requestparam-vs-pathvariable-annotations-in-spring-mvc/"><span style="color: red;">Spring MVC @RequestParam and @PathVariable annotations</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-30-mvc-hello-world-example/"><span style="color: red;">Spring MVC Hello World Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-exception-handling-example/"><span style="color: red;">Spring MVC Exception Handling Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-mvc-with-hibernate-crud-example/"><span style="color: red;">Spring MVC with Hibernate CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-tiles-plugin-with-example/"><span style="color: red;">Spring MVC Tiles Plugin with Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-and-interceptor-with/"><span style="color: red;">Spring MVC Interceptor with example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/integration-spring-mvc3-and-mongodb/"><span style="color: red;">Spring MVC with MongoDB CRUD Example</span></a></b></li>
<li><b><a href="https://dineshonjava.com/spring-3-mvc-internationalization/"><span style="color: red;">Spring MVC Internationalization &#038; Localization with Example</span></a></b></li>
<p></span></ol>
</div>
<p><b><i><b><b style="background-color: white; color: #222222; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><;<;</b><b style="background-color: white; color: #222222; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><a style="color: #888888;" href="https://dineshonjava.com/spring-web-mvc-framework-chapter-38/">Spring Web MVC Framework</a></b><b style="background-color: white; color: #222222; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"> |<a style="color: #888888;" href="https://dineshonjava.com/spring-tutorial/">index</a>| </b></b></i></b><b><i><b><b style="background-color: white; color: #222222; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: center; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><b style="background-color: white; color: #222222; font-family: Arial,Tahoma,Helvetica,FreeSans,sans-serif; font-style: normal; font-variant: normal; letter-spacing: normal; line-height: 18px; orphans: 2; text-align: left; text-indent: 0px; text-transform: none; white-space: normal; widows: 2; word-spacing: 0px;"><a style="color: #33aaff; text-decoration: underline;" href="https://dineshonjava.com/spring-3-mvc-internationalization/" target="_blank" rel="noopener">Spring 3 MVC Internationalization &; Localization with Example</a></b>>;>;</b> </b></i> </b></p>
</div>
</div>
<div class="wp-post-navigation"> 
									 <div class="wp-post-navigation-pre"> 
									 <a href="https://dineshonjava.com/spring-3-mvc-tiles-plugin-with-example/">Previous</a> 
									 </div> 
									 <div class="wp-post-navigation-next"> 
									 <a href="https://dineshonjava.com/spring-3-mvc-internationalization/">Next</a> 
									 </div> 
									</div>
<script type="text/javascript">
jQuery(document).ready(function($) {
 $.post('https://dineshonjava.com/wp-admin/admin-ajax.php', {action: 'mts_view_count', id: '614'});
});
</script>
Strategy Design Patterns We can easily create a strategy design pattern using lambda. To implement…
Decorator Pattern A decorator pattern allows a user to add new functionality to an existing…
Delegating pattern In software engineering, the delegation pattern is an object-oriented design pattern that allows…
Technology has emerged a lot in the last decade, and now we have artificial intelligence;…
Managing a database is becoming increasingly complex now due to the vast amount of data…
Overview In this article, we will explore Spring Scheduler how we could use it by…