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
|
public class ServletAuthentication extends HttpServlet {
static public final int ERREUR_LOGIN=0;
static public final short ERREUR_SESAME=1;
/**
* x x
*/
private static final long serialVersionUID = 1L;
// init
public void init() {
}
// GET
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String login = request.getParameter("UserLogin");
String pwd = request.getParameter("UserPassword");
int id_presta = -1;
System.out.println("LOGIN = " + login);
System.out.println("PWD = " + pwd);
if (login != null) {
//Connexion a MySQL pour savoir si le contractor existe
Connexion objcon = new Connexion();
Statement stmt = objcon.getStmt();
String query = "SELECT id_presta from prestataires where CONCAT(prenom_presta,'.',nom_presta) like '%"
+ login + "%' and id_presta IS NOT NULL ";
System.out.println(query);
try {
ResultSet rs = stmt.executeQuery(query);
if (rs.next()) {
id_presta = rs.getInt("id_presta");
System.out.println("idpresta: " + id_presta);
}
} catch (Exception e) {
e.printStackTrace();
}
if (id_presta != -1) {
request.setAttribute("id_presta", Integer.valueOf(id_presta));
request.getSession().setAttribute("id_presta", Integer.valueOf(id_presta));
getServletContext().getRequestDispatcher("/jsp/Planning.jsp")
.forward(request, response);
} else {
//Erreur de Login
getServletContext().getRequestDispatcher("/jsp/index.jsp?error="+ERREUR_LOGIN)
.forward(request, response);
}
}
}
// POST
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
// on passe la main au GET
doGet(request, response);
}
} |
Partager