Spring mvc is a Controller that responds to multiple requests. spring mvc

Source: Internet
Author: User

Spring mvc is a Controller that responds to multiple requests. spring mvc
1.1. controller implementation

Package com. morris. controller;

 

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 Users extends MultiActionController {

Public ModelAndView addUser (HttpServletRequest request,

HttpServletResponse response ){

ModelAndView mav = new ModelAndView ("hello ");

Mav. addObject ("message", "do addUser method ......");

 

Return mav;

}

Public ModelAndView updateUser (HttpServletRequest request,

HttpServletResponse response ){

ModelAndView mav = new ModelAndView ("hello ");

Mav. addObject ("message", "do updateUser method ......");

 

Return mav;

}

Public ModelAndView deleteUser (HttpServletRequest request,

HttpServletResponse response) throws Exception {

ModelAndView mav = new ModelAndView ("hello ");

Mav. addObject ("message", "do deleteUser method ......");

 

Return mav;

}

 

}

 

1.2. Spring-mvc.xml file configuration

<! -- Parse request parameter class -->

<Beanid ="ParameterMethodNameResolver"Class ="Org. springframework. web. servlet. mvc. multiaction. ParameterMethodNameResolver">

<Propertyname ="ParamName"Value ="Action"> </Property>

</Bean>

<! -- When the view parser returns a logical view, InternalResourceViewResolver adds the prefix and suffix -->

<Beanid ="InternalResourceViewResolver"Class ="Org. springframework. web. servlet. view. InternalResourceViewResolver">

<Propertyname ="Suffix"Value =". Jsp"> </Property>

<Propertyname ="Prefix"Value ="/"> </Property>

</Bean>

<Beanname ="/Users"Class ="Com. morris. controller. Users">

<Propertyname ="MethodNameResolver"Ref ="ParameterMethodNameResolver"> </Property>

</Bean>

1.3. Test

Enter the address in the browser:

Http: // localhost: 8080/HelloSpringMVC/users? Action = addUser

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.