Hi,
I am learning Spring MVC. I am trying to pass a url parameter from a page to itself when a form is submitted. Here is the code:
But when I submit the form, I am getting null value for var variable. Am I passing the variable correctly?Code:@Controller @RequestMapping(value = "/home.html") public class HomeController { @RequestMapping(method = RequestMethod.GET) public String showForm( @RequestParam(value = "var", required = false) String var, return "home"; } @RequestMapping(method = RequestMethod.POST) public ModelAndView addFeed( @RequestParam(value = "var", required = false) String var, @Valid FeedDomain feedDomain, BindingResult result, HttpServletRequest request, HttpServletResponse response) throws Exception { System.out.println("VAlue obained " + var); System.out.println(request.getParameter("var")); try { if (result.hasErrors()) { // if validator failed return new ModelAndView("home"); } else { ModelAndView modelAndView = new ModelAndView(new RedirectView("home?var=done")); return modelAndView; } } catch (Exception exception) { exception.printStackTrace(); throw exception; } } }


Reply With Quote
