我的控制器是:
@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";
}
}
答案 0 :(得分:0)
您不能在流程表单方法中设置用户名和密码,您必须从表单对象中读取它。
String userName = login form.getUserName();