Spring MVC试图在GET请求方法中从重定向获取参数

时间:2013-04-25 19:57:07

标签: java spring spring-mvc

我将表单发布到服务器,一旦表单成功,我想重定向到另一个页面但是我想将值发送到具有GET请求的重定向页面。我没有通过值:

错误 我收到HTTP 400错误请求错误

代码

@RequestMapping(value = "crime_registration_save.htm", method = RequestMethod.POST)
    public ModelAndView handleSave(@Valid @ModelAttribute Crime crime,BindingResult result, ModelMap m, Model model) throws Exception {



        if (result.hasErrors()) {

            logger.debug("Has Errors In crime_registration_save");
            model.addAttribute("dbcriminals", myCriminalList);
            model.addAttribute("dbvictims", myVictimList);
            model.addAttribute("status", myStatusList);
            model.addAttribute("crimeCategory", myCrimeCategoryList);
            model.addAttribute("crimeLevel", myCrimeLevelList);
            model.addAttribute("officers", myOfficerList);

            model.addAttribute("victimList", crime.getVictims());
            model.addAttribute("criminalList", crime.getCriminals());

            model.addAttribute("crimeTypeList",
                    crimeTypeManager.getCrimeTypeList(crime.getOffenceCatId()));
            model.addAttribute("icon", "ui-icon ui-icon-circle-close");
            model.addAttribute("results", "Error: Unable to Save Record!");

            return new ModelAndView("crime_registration");
        }
        logger.debug("No errors going to preform save");

        int crimeRecNo;

        crimeRecNo = crimeManager.saveCrime(crime); 

        return new ModelAndView(new RedirectView("monitoringList.htm")); 
    }

//-----------------------------------------------------------------------------------------
    @RequestMapping(value = "monitoringList.htm", method = RequestMethod.GET)
    public ModelAndView handleMonitoring(@RequestParam(value="crimeRecNo", required=true) Integer crimeRecNo, HttpServletRequest request,  
            HttpServletResponse response ,Model model) throws Exception {


        model.addAttribute("crimeRecNo", crimeRecNo);



        return new ModelAndView("monitoringList"); 
    }

1 个答案:

答案 0 :(得分:3)

RedirectView将模型对象传递给url。在您的示例中,没有从后处理程序方法返回的模型。

试试这个,它应该适合你:

return new ModelAndView(new RedirectView("monitoringList.htm"), "crimeRecNo", crimeRecNo);

希望这有帮助。