Spring MVC Multi Action Controller Example - Spring MVC Framework

What is Spring MVC - Multi Action Controller Example?

The following example explains the readers on how to use Multi Action Controller in forms using Spring Web MVC framework. This class is used in mapping multiple URLs to their methods in single controller respectively.

Let us consider an example using above configuration-

  • If URI is /home.htm, DispatcherServlet forwards the request to the UserController home() method.
  • If URI is user/add.htm, DispatcherServlet forwards the request to the UserController add() method.
  • If URI is user/remove.htm, DispatcherServlet forwards the request to the UserController remove() method.

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 name TestWeb under a package com.wisdomjobs as explained in the Spring MVC - Hello World Example chapter.

2

Create a Java classes UserController under the com. wisdomjobs package.

3

Create a view files home.jsp, user.jsp under jsp sub-folder.

4

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

UserController.java

TestWeb-servlet.xml

​home.jsp

user.jsp

Once the source and configuration files are created export the application. Do right click on the application andExport > WARFile option and save TestWeb.warfile 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 URLhttp://localhost:8080/TestWeb/home.htmand you must see the below result if everything is fine with Spring Web Application:

 Multi Action Controller Example

Try to hit the URL http://localhost:8080/TestWeb/user/add.htmyou will observe the below result.

 Multi Action Controller Example

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

Spring MVC Framework Topics