运行 应用程序时,bean 名称的 BindingResult 和普通目标对象都不是

Neither BindingResult nor plain target object for bean name when running application

index.jsp

<f:form action="emp_change.htm" method="POST" commandName="index">
                <div id="login_box">



                    <div id="form_val">
                        <div class="label">Username:</div>
                        <div class="control"><f:input path="emailId"  /></div>
                        <div style="clear:both;height:0px;"></div>
                        <div class="label">Password:</div>
                        <div class="control"><f:input path="password" type="password" /></div>
                        <div style="clear:both;height:0px;"></div>
                        <div id="msgbox"></div>
                        <div id="login_foot">
                            <input type="submit" name="action" id="login" value="Login" class="send_button" />
                        </div>                    
                    </div>
                </div>
            </f:form>

AdminInfoControl.java

@Controller
public class AdminInfoControl {

        private AdminInfoService service;

    @RequestMapping(value = "/emp_change", method = RequestMethod.POST)
    public String doActions(@ModelAttribute JtAdminInfo emp, BindingResult result, @RequestParam String action, Map<String, Object> map) {
        service = new AdminInfoService();
        JtAdminInfo empResult = new JtAdminInfo();
        switch (action.toLowerCase()) {

            case "login":
                JtAdminInfo search = service.getFindAdmin(emp.getEmailId());

                empResult = search != null ? search : new JtAdminInfo();
                break;
        }
        map.put("index", empResult);
        map.put("empList", service.getAll());
        return "index";
    }
}

我收到以下错误:

Neither BindingResult nor plain target object for bean name 'emp_change' available as request attribute

任何人都请帮助我更正此问题。如果信息不充分,请告诉我。

刚刚回答了几乎相同的问题。您在 doActions 方法中获取 emp_change 作为模型属性,但您之前没有将其设置为模型属性。因此,在某些方法中将 emp_change 设置为模型属性,例如显示您的 index.jsp 页面。像这样:

@RequestMapping(value = "/", method = RequestMethod.GET)
public ModelAndView showIndex() {
    ModelAndView mav = new ModelAndView("index");
    mav.addObject("emp_change", new JtAdminInfo ());
    return mav;
}

我在我的控制器中添加了以下方法并且工作正常。

    @RequestMapping("/index")
    public String setupForm(Map<String, Object> map) {
        map.put("index", new JtAdminInfo());
        return "index";
    }