Tuesday, July 8, 2014

Passing parameters from JSP to controller - Spring MVC

Instead of normal buttons you can have submit buttons and handle them in controller as below
  type="submit" value="Developer" name="developer">       
  type="submit" value="Graphic" name="graphic">
  type="submit" value="Cleaner" name="cleaner">
And you can have different methods in the controller class for each of the buttons clicked using the paramsattribute like this
@RequestMapping(value = "/redirect", method = {RequestMethod.POST}, params = "developer")
public ModelAndView developerMethod(){
}

 @RequestMapping(value = "/redirect", method = {RequestMethod.POST}, params = "graphic")
public ModelAndView graphicMethod(){
}

 @RequestMapping(value = "/redirect", method = {RequestMethod.POST}, params = "cleaner")
public ModelAndView cleanerMethod(){
}

No comments:

Post a Comment