Bonjour,
J'ai ce message d'erreur et je ne comprends pas d'où ça vient ?
Neither BindingResult nor plain target object for bean name 'command' available as request attribute
mon contrôleur :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
| @Controller
@RequestMapping("/connect")
public class Connecter {
@InitBinder
public void initBinder(WebDataBinder dataBinder){
dataBinder.setRequiredFields(new String[] {"login", "password"});
}
@RequestMapping(method = RequestMethod.POST)
public String welcome(HttpServletRequest request, ConnectForm form,
BindingResult r) {
String page = "/produit.jsp";
if (request.getSession().getAttribute("client") == null) {
ConnectFormValidator validator = new ConnectFormValidator();
validator.validate(form, r);
if (!r.hasErrors()) {
IDAOFactory factory = DAOFactory.getInstance();
IClient client = factory.getDAOClient().selectClient(
request.getParameter("login"),
request.getParameter("login").toCharArray());
if (client != null) {
page = "compte.jsp";
request.getSession().setAttribute("client", client);
}
}
}
return page;
} |
ma page jsp est :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
|
<?xml version="1.0" encoding="UTF-8" ?>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Welcome page</title>
</head>
<body>
<div style="text-align:right">
<c:if test="${empty client}">
<form:form action="connect.spr" method="post" >
<label>Login : </label>
<form:input path="login" size="8" maxlength="8" />
<form:errors path="login" /><br/>
<label> Mot de passe :</label>
<form:input path="password" size="8" maxlength="8" />
<form:errors path="password" /><br/>
<input type="submit" value="se connecter"/><br/>
</form:form>
</c:if>
<div><a href="#">Mon compte</a></div>
</div>
</body>
</html> |
mon validator :
1 2 3 4 5 6 7 8
| public void validate(ConnectForm form, Errors errors) {
if (form.getLogin() == null || form.getLogin().isEmpty()) {
errors.rejectValue("login", "required", "must not be empty");
} else if (form.getPassword() == null || form.getPassword().isEmpty()) {
errors.rejectValue("password", "required", "must not be empty");
}
} |
Partager