Bonjour,
Je travaille avec eclipse Helios JEE et un serveur tomcat 7
J'ai créer un projet tout simple avec :
Dans src, un package bean et une classe Personne dont voici le contenu :
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
44
45
46
47
48
49
50 package bean; import javax.faces.application.FacesMessage; import javax.faces.context.FacesContext; public class Personne { private String nom; private String prenom; private String motDePasse; public Personne() { super(); } public String loginUser() { Personne personneAutorise = new Personne(); personneAutorise.setNom("admin"); personneAutorise.setMotDePasse("admin"); if(personneAutorise.getNom().equalsIgnoreCase(this.getNom()) && personneAutorise.getMotDePasse().equals(this.getMotDePasse())) return "success"; FacesContext facesContext = FacesContext.getCurrentInstance(); FacesMessage facesMessage = new FacesMessage("Vous avez entré un couple utilisateur/mot de passe incorrect!"); facesContext.addMessage("loginForm", facesMessage); return "failure"; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } public String getMotDePasse() { return motDePasse; } public void setMotDePasse(String motDePasse) { this.motDePasse = motDePasse; } }
Voici la configuration de mon dossier WebContent :
Avec comme contenu de web.xml :
et faces-config.xml
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 <?xml version="1.0"?> <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd"> <web-app> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>javax.faces.CONFIG_FILES</param-name> <param-value>/WEB-INF/faces-config.xml</param-value> </context-param> <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> <!-- Faces Servlet --> <servlet> <servlet-name>Faces Servlet</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup> 1 </load-on-startup> </servlet> <!-- Faces Servlet Mapping --> <servlet-mapping> <servlet-name>Faces Servlet</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> </web-app>
puis la page 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 <?xml version="1.0"?> <!DOCTYPE faces-config PUBLIC "-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN" "http://java.sun.com/dtd/web-facesconfig_1_1.dtd"> <faces-config> <navigation-rule> <from-view-id>/pages/login.jsp</from-view-id> <navigation-case> <from-outcome>greeting</from-outcome> <to-view-id>/pages/accueil.jsp</to-view-id> </navigation-case> </navigation-rule> <managed-bean> <managed-bean-name>personBean</managed-bean-name> <managed-bean-class>bean.Personne</managed-bean-class> <managed-bean-scope>request</managed-bean-scope> </managed-bean> </faces-config>
et lorsque je lance le projet ma page jsp m'affiche ceci :
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 <%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %> <%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %> <html> <head> <title>enter your name page</title> </head> <body> <f:view> <h1> <h:outputText value="JSF Hello World"/> </h1> <h:form id="helloForm"> <h:outputText value="Quel est votre nom :"/> <h:inputText value="#{personBean.nom}" /> <h:commandButton action="greeting" value="Saluer" /> </h:form> </f:view> </body> </html>
des idées ???
Merci
Partager