I want to send "Value" from one of the Radio Buttons to SpringMVC, but I watch the problem where I didn't expect. And I has read similar answers on my topic, but I hasn't found the answer on my question HTML:
<form action="addRadio" method="post" >
<input type="radio" name="rbn" id="rbn" value="Red"/>Red
<input type="radio" name="rbn" value="White"/>White
<input type="radio" name="rbn" value="Blue"/>Blue
<input type="radio" name="rbn" value="Yellow"/>Yellow
<input type="submit" value="Submit"/>
</form>
Try recieve in Java:
@Controller
public class testController {
@RequestMapping(name = "/test", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView seeTest(){
ModelAndView m = new ModelAndView();
m.setViewName("addFabric/testRadio");
return m;
}
@RequestMapping(name = "/addRadio", method = {RequestMethod.GET, RequestMethod.POST})
public ModelAndView add(@RequestParam(value = "rbn", required = false) String name){
ModelAndView modelAndView = new ModelAndView();
System.out.println("Type Radio: "+name);
modelAndView.setViewName("index");
return modelAndView;
}
} And I recieve this mistake:
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'requestMappingHandlerMapping'
defined in class path resource [org/springframework/boot/autoconfigure/web/WebMvcAutoConfiguration$EnableWebMvcConfiguration.class]:
Invocation of init method failed; nested exception is java.lang.IllegalStateException: Ambiguous mapping. Cannot map '/test' method
public org.springframework.web.servlet.ModelAndView margo.controller.add.testController.seeTest()
to {[],methods=[GET || POST]}: There is already 'addTestController' bean method
public org.springframework.web.servlet.ModelAndView margo.controller.add.addTestController.add(java.lang.String) mapped.
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1589) ~[spring-beans-4.3.5.RELEASE.jar:4.3.5.RELEASE]