0

i am new in spring. and i am developing login application in spring mvc . while setting the values in LoginForm its is showing "null". please help me. want to get out of it!! Any help will be appriciated.

My controller is:

@Controller
@RequestMapping("loginform.html")
public class LoginController extends MainController {
    private String password;
    private LoginDAO loginDAO;

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    @RequestMapping(method = RequestMethod.GET)
    public String showForm(Map model) {
        LoginForm loginForm = new LoginForm();
        model.put("loginForm", loginForm);
        return "loginform";
    }

    @RequestMapping(method = RequestMethod.POST)
    public String processForm(@Valid LoginForm loginForm, BindingResult result,
            Map model) {
        //String userName = "Admin";
        //String password = "root";
        if (result.hasErrors()) {
            return "loginform";

        }

        try {

            loginForm.setUserName(userName);
            loginForm.setPassword(password);
            loginDAO = new LoginDAOImpl();
            LoginForm tempLoginForm = loginDAO.validateUser(loginForm);
            if (tempLoginForm == null) {

                return "loginsuccess";
            }

        } catch (Exception e) {

        }

        model.put("loginForm", loginForm);
        return "loginerror";
    }
}
4

1 回答 1

0

过程表单方法中不能设置用户名和密码,必须从表单对象中读取。

String userName = login form.getUserName();
于 2013-06-24T08:57:45.120 回答