Spring MVC Simple Url Handler Mapping Example - Spring MVC Framework

What is Spring MVC - Simple Url Handler Mapping Example?

The following example explains the readers on how to use Simple Url Handler Mapping in forms using Spring Web MVC framework. This class is used in mapping URLs to their controllers respectively.

Let us consider an example using above configuration-

  1. If URI is /helloWorld.htm, DispatcherServlet forwards the request to the HelloController.
  2. If URI is /welcome.htm, DispatcherServlet forwards the request to the WelcomeController.

Firstly, a working Eclipse IDE should be in place and follow the steps below to create a Dynamic Form based Web Application

Step

Description

1

Create a project with a nameTestWebunder a packagecom. wisdomjobs as explained in theSpring MVC - Hello World Examplechapter.

2

Create a Java classesHelloController,WelcomeControllerunder thecom. wisdomjobs package.

3

Create a view fileshello.jsp,welcome.jspunderjspsub-folder.

4

The final step is to create the content of all the source and configuration files and export the application as explained below.

HelloController.java

WelcomeController.java

TestWeb-servlet.xml

hello.jsp

welcome.jsp

Once the source and configuration files are created export the application. Do right click on the application and Export > WAR File option and save TestWeb.war file in Tomcat’s webapps folder.

Start the Tomcat Server and using a standard browser check if you are having access to other web pages from webapps folder. Try the URL http://localhost:8080/TestWeb/helloWorld.htm and you must see the below result if everything is fine with Spring Web Application:

 Simple Url Handler Mapping Example

Try to hit the URL http://localhost:8080/TestWeb/welcome.htm you will observe the below result.

 Simple Url Handler Mapping Example

All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd DMCA.com Protection Status

Spring MVC Framework Topics