IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Servlets/JSP Java Discussion :

Problème servlet d'Authentification


Sujet :

Servlets/JSP Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Profil pro
    Inscrit en
    Mai 2010
    Messages
    10
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Mai 2010
    Messages : 10
    Par défaut 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 : 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
    <!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>&nbsp;</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" />&nbsp;&nbsp;
          <input name="Enter"  id="search_btn" type="submit" onclick="ins();" value="Enter" />
        </p>
      </center>
    </form>
    <p>&nbsp;</p>
    <p class="momo">&nbsp;</p>
    </div>
    </body>
    ma servlet
    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
    //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();
     
        }
    }
    }

  2. #2
    Membre éclairé
    Inscrit en
    Février 2008
    Messages
    64
    Détails du profil
    Informations forums :
    Inscription : Février 2008
    Messages : 64
    Par défaut
    Bonsoir,

    vous n'avez pas bien expliqué votre problème!!! il parait que t'as mis action='Servlet_Authen.java' alors je crois qu'il faut mettre seulement action='Servlet_Authen'. la servlet est déjà compilé, elle n'est plus .java et après dé-commentes la ligne au dessous(le submit). je parle toujours du code javascript

  3. #3
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    En n'oubliant pas de faire le mapping entre l'action formulaire et la classe servlet qui doit executer la requete, ce dans ton web.xml

Discussions similaires

  1. problème servlet xml
    Par youp_db dans le forum Tomcat et TomEE
    Réponses: 3
    Dernier message: 02/10/2006, 15h46
  2. problème servlet + JDBC sur tomcat
    Par pellec dans le forum Tomcat et TomEE
    Réponses: 2
    Dernier message: 09/08/2006, 09h45
  3. Réponses: 4
    Dernier message: 18/05/2006, 09h54
  4. [SQL Server]Problème avec l'authentification SQL SERVER
    Par tidou dans le forum MS SQL Server
    Réponses: 2
    Dernier message: 20/04/2005, 15h40
  5. [Débutant] Problème servlet simple
    Par davycrocket dans le forum Servlets/JSP
    Réponses: 7
    Dernier message: 30/06/2004, 09h24

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo