devdar
devdar

Reputation: 5654

Spring MVC trying to get parameter from redirect in GET request method

I POST a form to the server and once the form is sucessful i want to redirect to another page however i want to send values to the redirect page which has a GET request. I am not getting the values to pass:

Error I am getting a HTTP 400 Bad Request error

Code

@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"); 
    }

Upvotes: 1

Views: 2924

Answers (1)

Akshay
Akshay

Reputation: 3198

RedirectView passes the model objects to the url. In your example, there is no model being returned from the post handler method.

Try this, and it should work for you:

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

Hope this helps.

Upvotes: 3

Related Questions