Problème servlet d'Authentification
Bonjour a tous,
je suis entrain de développer ma 1ère application en servlets/jsp donc j'ai rencontré un problème dans l'authentification des utilisateurs toute aide sera la bienvenue. Merci d'avance
Ma page d'authentification:
Code:
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
| <!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=iso-8859-1" />
<title>Security Policy</title>
<link href="main.css" rel="stylesheet" type="text/css" />
<script>
function ins()
{
if(document.form1.password.value.length==0|| document.form1.login.value.length==0)
alert("must complete all mandatory fields");
else
{
document.form1.action='Servlet_Authen.java';
//document.form1.submit();
}
}
</script>
<style type="text/css">
<!--
.momo {
font-family: Times New Roman, Times, serif;
}
.momo {
color: #000;
font-weight: bold;
}
.momo {
font-size: large;
}
-->
</style>
</head>
<body onload="MM_preloadImages('images/genilogo.bmp')">
<p align="center" class="titre">Welcome</p>
<div align="justify">
<p class="momo" style="size:20px">You should sign in to configure your Security Policy
</p><form method="get" name="form1" id="form1">
<center>
<table width="594" border="0">
<tr>
<div class="ins">
<td class="ins">*Login</td>
<td class="ins"><input class="champtext" name="login" type="text" maxlength="30" /></td>
</div>
</tr>
<tr class="ins">
<p> </p>
<div class="ins">
<td>*Password</td>
<td> <input class="champtext" name="password" type="password" maxlength="30"/> </td>
</div>
</tr>
</table>
</center>
<center>
<p>
<input name="Reset" id="search_btn" type="reset" value="Reset" />
<input name="Enter" id="search_btn" type="submit" onclick="ins();" value="Enter" />
</p>
</center>
</form>
<p> </p>
<p class="momo"> </p>
</div>
</body> |
ma servlet
Code:
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
| //package Servlets;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.IOException;
import java.sql.*;
public class Servlet_Authen extends HttpServlet {
public class Authentification {
private Connection c;
private Statement stmt;
public Authentification()throws ClassNotFoundException, SQLException
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
c = DriverManager.getConnection("jdbc:odbc:DBAdmin");
stmt = c.createStatement();
}
public boolean verification(String login,String password)throws SQLException
{
ResultSet rs1 = stmt.executeQuery("select * from DBAdmin.administrateur");
boolean verif=false;
while(rs1.next())
{
if((login.equals(rs1.getString(2)))& (password.equals(rs1.getString(3))))
{
verif= true;
}
//System.out.println(rs1.getString(2));
}
return verif;
}
public void liste() throws SQLException
{
ResultSet rs = stmt.executeQuery("select * from DBAdmin.administrateur");
while(rs.next()){
System.out.println(rs.getString(3));}
}
}
public void doGet( HttpServletRequest req, HttpServletResponse response)
throws ServletException, IOException {
// get stream to output HTML on!
response. setContentType("text/html");
PrintWriter out = response. getWriter();
String login = req. getParameter("login");
String password = req. getParameter("password");
// System.out.println(login+password);
HttpSession session = req.getSession(true);
session.setAttribute("login", login);
try{
Authentification authentification = new Authentification();
if (authentification.verification(login,password))
{
RequestDispatcher dispat = getServletContext().getRequestDispatcher("/Accueil_auth.html");
dispat.forward(req,response);
}
else {
}
}
catch(Exception e){
e.printStackTrace();
}
}
} |