Spring MVC
MultiactionController
In
Spring MVC application, MultiActionController
class
you can group related actions into a single controller class. The
handler method for each action should be in the following form.
public (ModelAndView | Map | String | void) actionName(HttpServletRequest request,HttpServletResponse response,[,HttpSession[,AnyObject]);
home.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>JSL Tech Spring MVC Welcome to Spring MultiactionController
Login
ViewList
Search
UserController.java
package com.jsl.springmvc.example; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.mvc.multiaction.MultiActionController; public class UserController extends MultiActionController { public ModelAndView login(HttpServletRequest request,HttpServletResponse response) throws Exception{ return new ModelAndView("viewMessage", "message","Login method is invoked"); } public ModelAndView viewList(HttpServletRequest request,HttpServletResponse response) throws Exception{ return new ModelAndView("viewMessage", "message","viewList method is invoked"); } public ModelAndView search(HttpServletRequest request,HttpServletResponse response) throws Exception{ return new ModelAndView("viewMessage", "message","Search method is invoked"); } public ModelAndView home(HttpServletRequest request,HttpServletResponse response) throws Exception{ return new ModelAndView("home"); } }
welcome-servlet.xml
The requests comes with .do will be handled by UserController. It checks the uri with the method by InternalPathMethodNameResolver
And your director structure looks like this:
No comments:
Post a Comment