Bonjour,
Je réalise une application web ou j'utilise éclipse indigo, tomcat 7.0, Hibernate 4.1.1 et Spring 3.1.1.
Lorsque je vais sur ma page login, la console m'affiche le message d'erreur suivant :
org.apache.jasper.JasperException: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'loginform' available as request attribute
Voici le code de mon fichier login.jsp
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39
40
41
42
43 <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@ taglib uri="http://www.springframework.org/tags/form" prefix="form"%> <!-- tests --> <% //session.removeAttribute("nom"); int nb_p = 7; String[] st = new String[50]; for(int i=1; i <= nb_p; i++) st[i-1]="Playlist "+i; session.setAttribute("playlists", st);%> <!-- header --> <jsp:include page="HeaderFooter/header.jsp"/> <!-- side menu --> <jsp:include page="Content/side_menu.jsp"/> <!-- content --> <div class="span9"> <form:form modelAttribute="loginform" action="/VinylRecordManager/login" method="POST"> <div class="well"> <h1>Connexion</h1> <p>Utilisez votre nom d'utilisateur et votre mot de passe pour accéder à votre compte.</p> </div> <div class="span7 well"> <form:label path="userName">Nom d'utilisateur</form:label> <form:input path="userName"/> <form:label path="password">Mot de passe</form:label> <form:input path="password"/> </div> <div class="span7 well"> <div class="btn-toolbar pull-right"> <div class="btn-group"> <a class="btn" href="register.jsp">Je n'ai pas de compte utilisateur »</a> </div> <div class="btn-group"> <input type="submit" class="btn" value="Valider"> <a class="btn" href="index.jsp">Accueil</a> </div> </div> </div> </form:form> </div><!--/span--> <!-- footer --> <jsp:include page="HeaderFooter/footer.jsp"/>
formulaire java
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package app.web; public class LoginForm { private String userName; private String password; public void setUserName(String userName) { this.userName = userName; } public String getUserName() { return userName; } public void setPassword(String password) { this.password = password; } public String getPassword() { return password; } }
Controlleur
Merci d'avance
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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
35
36
37
38
39 package app.web; import javax.servlet.http.HttpSession; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.validation.BindingResult; import org.springframework.web.bind.annotation.ModelAttribute; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.ui.Model; import app.service.UserService; @Controller("LoginController") @RequestMapping("/VinylRecordManager/login") public class LoginController { @Autowired private UserService user; @RequestMapping(method = RequestMethod.GET) public String getForm(Model model) { model.addAttribute("loginform", new LoginForm()); return "login"; } @RequestMapping(method = RequestMethod.POST) public String Authentification(@ModelAttribute("loginform") LoginForm lform, HttpSession session, BindingResult result) { if (user.login(lform.getUserName(), lform.getPassword())==true) System.out.println("authentifie"); else System.out.println("error"); return "index"; } }
Partager