如何转换SimpleFormController?

时间:2018-03-15 12:29:14

标签: java spring spring-mvc

目前我正在使用SimpleFormController,但我正在使用javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Neither BindingResult nor plain target object for bean name 'name' available as request attribute

所以这是我的代码,但我不知道如何转换它

public LoginController() {
        setCommandClass(Customer.class);
        setCommandName("name");
        setSuccessView("userAccount");
        setFormView("loginView");
    }
    @Override
    protected ModelAndView onSubmit(Object command) throws Exception {
        Customer name = (Customer) command;
        ApplicationContext ac = new
            ClassPathXmlApplicationContext("ICHDApp/Spring-Config.xml");
        Account act = (Account) ac.getBean("AccountBean");
        ModelAndView mv = new ModelAndView();
        mv.addObject("helloMessage", loginService.sayHello(name.getUserName()));
        String str = ("Account Number:"+act.getAccountNumber());
        mv.addObject("accountNumber", str);
        String str1 = ("Account Balance ($):"+act.getBalance());
        mv.addObject("accountBalance", str1);
        mv;
    }

那么整个代码会有什么变化?

1 个答案:

答案 0 :(得分:0)

我在代码中看到的问题是你没有将任何对象传递给“name”