Nearby lessons

19 of 35

Spring - MultiActionController

📌 What You Will Learn
  • Understand Spring - MultiActionController
  • See working code examples
  • Learn from common mistakes and Q&A

Learn Spring - MultiActionController step by step — simple explanations, complete programs with their output, common beginner mistakes, and exam-style MCQs.

MultiActionController — web.xml

Example01
Loading editor…

Internal Flow

handleRequestInternal() method will be executed, it will return "viewName" property value as ModelAndView object , that is, logical name of the View, where ViewResolver will resolve the View Page and generate the respective webpage as response.

EX:

public class ParameterizableViewController extends Abstractcontroller{

public ModelAndView handleRequestInternal(HttpServletRequest request, HttpservletResponse response)throws Exception{

return new ModelAndView(getViewName()); } }

MultiActionController

In general, in Spring WEB MVC applications, we will for each and every form or an URI we will prepare a separate Controller class depending on our requirement.

In the above approach, if we want to provide a particular Entity related actions like save, update, search and delete then we have to prepare seperate Controller classes like SaveController, UpdateController, SearchController, DeleteController... it will increase no of controller classes unnecessarily. In the above context, to reduce no of controller classes, SPring Framework has provided an alternative in the fomr of

"org.springframework.web.servlet.mvc.multiaction.MultiActionController".

The main intention of MultiActionController class is to group related actions into a single controller class.

If we want to use MultiAction controller class in Spring WEB MVC applications then we have to declare an user defined class as sub class to "MultiActionController" and we have to define action methods with the same incoming URI names.

public (ModelAndView | Map | String | void) actionName(HttpServletRequest request, HttpServletResponse response);

Example03
Loading editor…

MultiActionController — index.jsp

Example:

Example04
Loading editor…

MultiActionController — home.jsp

Example05
Loading editor…

MultiActionController — addform.jsp

Example06
Loading editor…

MultiActionController — searchform.jsp

Example07
Loading editor…

MultiActionController — updateform.jsp

Example08
Loading editor…

MultiActionController — student_edit_form.jsp

Example09
Loading editor…

MultiActionController — deleteform.jsp

Example10
Loading editor…

MultiActionController — student.jsp

Example11
Loading editor…

MultiActionController — status.jsp

Example12
Loading editor…

MultiActionController — HomeController.java

Example13
Loading editor…

MultiActionController — StudentAction.java

Example14
Loading editor…

MultiActionController — StudentDao.java

Example15
Loading editor…

MultiActionController — StudentTo.java

Example16
Loading editor…

MultiActionController — ds-servlet.xml

Example17
Loading editor…

MultiActionController — web.xml

Example18
Loading editor…

MultiActionController

To run the above application we need the following jar files in web application lib folder. o commons-logging-1.2.jar o ojdbc6.jar o spring-aop-4.3.9.RELEASE.jar o spring-aspects-4.3.9.RELEASE.jar o spring-beans-4.3.9.RELEASE.jar o spring-context-4.3.9.RELEASE.jar o spring-context-support-4.3.9.RELEASE.jar o spring-core-4.3.9.RELEASE.jar

📝 Key Takeaways
  • Key ideas of Spring - MultiActionController explained simply
  • Ready-to-use code examples
  • Exam-style questions at the end

Finished this lesson?

Mark it as complete to track your progress and see technology completion stats.