j'ai un petit probleme au niveau du developpement de l'application web pour la gestion des intervention informatique :
je vous explique le probleme exactemnt :
j'ai une table Intervenant qui contiens : username, password, type ( le type c'est sois Admin sois simple user)
et moi je veux separer les pages de chaqu'un, l'admin aura sa propore page avec ses propore fonctionalitèes,et le user normal aussi
j'ai reussi a faire cela.. mais le probleme qui se pose : quand je rentre un faux username/password il de retourn NullPointerException..alors qu'il dois m'ouvrir une page qui affichera ( username/password incorrecte !! )
j'ai beau essayè et reessayè, j'y arrive vraiment pas .. je suis bloquè a ce point et je dois avancer et viite, parce que c mon PFE
je demande l'aide des Expert dans le domain. je vous de me corrier cette erreur..
technologie utilisè : JEE JSF
la classe Intervenant :
LoginDAO :
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87 package com.intervention.jsf.beans; import java.sql.SQLException; import javax.faces.application.FacesMessage; import javax.faces.bean.ManagedBean; import javax.faces.bean.SessionScoped; import javax.faces.context.FacesContext; import javax.servlet.http.HttpSession; import com.intervention.jsf.dao.LoginDAO; @ManagedBean @SessionScoped public class intervenant { private int id_intervenant; private String login; private String password; private String type; public int getId_intervenant() { return id_intervenant; } public void setId_intervenant(int id_intervenant) { this.id_intervenant = id_intervenant; } public String getLogin() { return login; } public void setLogin(String login) { this.login = login; } public String getPassword() { return password; } public void setPassword(String password) { this.password = password; } public String getType() { return type; } public void setType(String type) { this.type = type; } public intervenant(int id_intervenant, String login, String password, String type) { super(); this.id_intervenant = id_intervenant; this.login = login; this.password = password; this.type = type; } public intervenant() { super(); // TODO Auto-generated constructor stub } public String validateUsernamePassword() throws SQLException { String test=null; String valid = LoginDAO.validate(login, password); if (valid.equals("admin")) { HttpSession session = SessionBean.getSession(); session.setAttribute("username", login); test="admin"; } else if (valid.equals("intervenant")) { HttpSession session = SessionBean.getSession(); session.setAttribute("username", login); test= "intervenant"; } else if(valid.equals("null")) { HttpSession session = SessionBean.getSession(); session.setAttribute("username", login); test= "fail"; } return test; } //logout event, invalidate session public String logout() { HttpSession session = SessionBean.getSession(); session.invalidate(); return "login"; } }
MERCI BCP
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 package com.intervention.jsf.dao; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import com.intervention.jsf.util.DataConnect; public class LoginDAO { public static String validate(String user, String password) throws SQLException { Connection con = null; PreparedStatement ps = null; String type=null; con = DataConnect.getConnection(); ps = con.prepareStatement("Select login, password,type from intervenant where login = ? and password = ?"); ps.setString(1, user); ps.setString(2, password); ResultSet rs = ps.executeQuery(); if (rs.next()) { type=rs.getString(3); } if(type.equals(null)) return "null"; return type; } }
Partager