I have two submit buttons in my JSP add,remove. I don’t really know how to differentiate the operations in the controller side.
<form:form modelAttribute="emp" action="/empl" method="POST">
<input type="submit" name="operation" value="Remove"/>
<input type="submit" name="operation" value="Add" />
</form:form>
@RequestMapping(value = "/empl", method = RequestMethod.POST)
public String getD(@Valid Em form, BindingResult result, Model model) {//code}
Onclick of the either button posts values correctly along with “operation Add” or “operation Remove” respectively and then add works because that is the default method being called. Now how do i catch the operation parameter and differentiate the operation and use it?
The browser will provide a request parameter containing the name of the submit button that was pressed. You can then use those to filter:
Each of these can then call shared logic as required.