In your use case, two actions are required:
- View and edit
<form> - Submit
<form>
This should be mapped to two handler methods
@RequestMapping(method = RequestMethod.GET) public String getForm() { model.addAttribute("message", "Hello Mahdi"); return "hello"; // assume hello.jsp } @RequestMapping(params={"submit"}, method = RequestMethod.GET) public String printWelcome(ModelMap model, @RequestParam(value = "xx",required=true) String xx) { /* Do something with submitted parameter and return some view name */ }
When you want to access the form, you do a GET on / . When you submit the form, you can also do a GET before / , but you need something else to distinguish the request. Here I used params="submit" . So you need to change your input file to
<input type="submit" name="submit">submit</button>
or just put the parameter that you are already using ( params={"xx"} ).
source share