Post method is not executed when get method is invoked by ModelAndView from different method.

298 views Asked by At

I need help.

Post method is not executed when get method is invoked by ModelAndView from different method.

Get method for mapping2 is correctly populated with data(taken from ModelAttribute), but when I'm pressing form Submit button it is not executing post method for mapping2. It's running GET method all the time.

Url is mapping1 and it is not changing to mapping2, just jsp for mapping2 is displayed as content of mapping1.

Do you have any idea how to run post method?

The code from controller below.

@RequestMapping(value = "/mapping1", method = RequestMethod.POST)
public ModelAndView addItem(
        @RequestParam(value = "year", required = true) final BigDecimal year,
        @ModelAttribute("item") final Item item,
        final HttpServletRequest request) {

    ModelAndView mav = new ModelAndView("mapping2");        
    mav.addObject("item", item);

            return mav;
}


@RequestMapping(value = "/mapping2", method = RequestMethod.GET)
public Item addItemConfirmation(
        @ModelAttribute("item") final Item item,
        final HttpServletRequest request) {

    return item;
}

@RequestMapping(value = "/mapping2", method = RequestMethod.POST)
public String addItemConfirmation(
        @ModelAttribute("Item") final Item item,
        final HttpServletRequest request) {

            operations on item...

    itemDAO.persist(item);                      

    return "redirect:/itemAddSuccess

}

0

There are 0 answers