SpringMVC RadioButton表单不起作用

时间:2015-10-27 16:03:12

标签: jsp spring-mvc

我是初学者,正在与SpringMVC斗争。 Form是一行RadioButtons。目标是,单击“提交”时,使用当前存储在模型中的选择重新显示此表单。

我当前的错误:

java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'command' available as request attribute

Controller:SFController.java

@Controller
public class SFController {


    @RequestMapping("/sf")
    public ModelAndView showInitial(final HttpServletRequest request) {

        ModelAndView mav = new ModelAndView("/WEB-INF/jsp/forms/sf.jsp", "sfModel", new SFModel());                                

        return mav;
    }

    @RequestMapping("/sfResult")
    public ModelAndView showResult(final HttpServletRequest request, 
                                   @ModelAttribute SFModel sfModel) {


        ModelAndView mav = new ModelAndView("/WEB-INF/jsp/forms/sf.jsp", "sfModel", sfModel);                                

        return mav;
    }

JSP(sf.jsp)

    <form:form method="POST" action="/sfResult">            


            <form:radiobutton path="type" value="a" />a <br/>
            <form:radiobutton path="type" value="b" />b.<br/>
            <form:radiobutton path="type" value="c" />c <br/>
            <form:radiobutton path="type" value="d" />d <br/>
            <form:radiobutton path="type" value="e" />e <br/>

        <input value="Submit" type="submit">  

    </form:form>

Model,SFModel.java:

public class SFModel {

    private String type;

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }   
}

1 个答案:

答案 0 :(得分:0)

固定。我在JSP中的Form标记中缺少命令名称引用。

<form:form method="POST" commandName="sfModel" action="/sfResult">