0

I am using the following controller for a parameter-method resolution.

@Controller
@RequestMapping("/customer")
public class CustomerController extends MultiActionController{

    @RequestMapping(params = "action=add")
    public ModelAndView add(HttpServletRequest request,
        HttpServletResponse response) throws Exception {

        return new ModelAndView("CustomerPage", "msg","add() method");

    }
....
....
}

However,this makes the url of the following format to work:

http://localhost:7001/begin-mvc/customer/?action=update

How do I get this to work for /customer/*.htm?action=.....

IUnknown
  • 9,301
  • 15
  • 50
  • 76

1 Answers1

0

I think you could do the following:

@Controller

@RequestMapping("/customer")
public class CustomerController extends MultiActionController{

    @RequestMapping(value="{myHtmFile:.*\\.htm}", params = "action=add")
    public ModelAndView add(HttpServletRequest request,
        HttpServletResponse response, @PathVariable String myHtmFile) throws Exception {

        return new ModelAndView("CustomerPage", "msg","add() method");

    }
....
....
}

This uses RegEx to match the pattern. The regex may need some work, but that's the general idea. As a bonus, I show how you can assign the variable using the @PathVariable. If you don't want to do that, I think you can just include the regex in the {} and drop the @PathVariable.

CodeChimp
  • 8,016
  • 5
  • 41
  • 79