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

AWT/Swing Java Discussion :

creation une session


Sujet :

AWT/Swing Java

  1. #1
    Membre éclairé
    Inscrit en
    Avril 2007
    Messages
    679
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 679
    Par défaut creation une session
    salut je n'arrive pas a créer une session
    j'ai une table utilisateur et je cherche faire l'accée avec creation une session
    voila
    code
    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
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
     
     import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpSession;
    import javax.swing.SwingUtilities;
    import javax.swing.JPanel;
    import javax.swing.JFrame;
    import java.awt.Rectangle;
    import javax.swing.ImageIcon;
    import javax.swing.JLabel;
    import java.awt.Color;
    import javax.swing.JTextField;
    import javax.swing.JOptionPane;
    import javax.swing.JPasswordField;
    import java.awt.Font;
    import javax.swing.JButton;
    import java.awt.SystemColor;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.ResultSet;
    import java.sql.Statement;
     
    public class david extends JFrame {
    /**
             * 
             */
    	private static final long serialVersionUID = 1L;
    JPanel jContentPane = null;
    private JPanel jPanel = null;
    private JTextField jTextField = null;
    private JPasswordField jPasswordField = null;
    private JButton jButton = null;
    private JLabel jLabel = null;
    private JLabel jLabel1 = null;
    private JPanel getJPanel() {
    		if (jPanel == null) {
    			jLabel1 = new JLabel();
    			jLabel1.setBounds(new Rectangle(100, 115, 92, 30));
    			jLabel1.setText("Mot de passe :");
    			jLabel = new JLabel();
    			jLabel.setBounds(new Rectangle(100, 66, 95, 30));
    			jLabel.setText("Nom utilisateur :");
    			jPanel = new JPanel();
    			jPanel.setLayout(null);
    			jPanel.setBounds(new Rectangle(8, 5, 481, 476));
    			jPanel.setBackground(new Color(0, 138, 255));
    			jPanel.add(getJTextField(), null);
    			jPanel.add(getJPasswordField(), null);
    			jPanel.add(getJButton(), null);
    			jPanel.add(jLabel, null);
    			jPanel.add(jLabel1, null);
     
    		}
    		return jPanel;
    	}
     
     
     
     
     
     
    	/**
             * This method initializes jTextField   
             *      
             * @return javax.swing.JTextField       
             */
    	private JTextField getJTextField() {
    		if (jTextField == null) {
    			jTextField = new JTextField();
    			jTextField.setBounds(new Rectangle(235, 66, 148, 30));
    		}
    		return jTextField;
    	}
     
     
     
     
    private JPasswordField getJPasswordField() {
    	if (jPasswordField == null) {
    		jPasswordField = new JPasswordField();
    		jPasswordField.setBounds(new Rectangle(235, 115, 148, 30));
    		jPasswordField.setFont(new Font("Dialog", Font.PLAIN, 18));
    	}
    	return jPasswordField;
    }
     
     
    private JButton getJButton() {
    	if (jButton == null) {
    		jButton = new JButton();
    		jButton.setBounds(new Rectangle(269, 174, 98, 26));
    		jButton.setForeground(SystemColor.desktop);
    		jButton.setText("Connection");
    		jButton.setBackground(Color.orange);
    		jButton.addActionListener(new java.awt.event.ActionListener() {
    			public void actionPerformed(java.awt.event.ActionEvent e) {
    				 String  nom = jTextField.getText();
    				 String passe1 =	jPasswordField.getText().trim();	
    				 String prenom="";
    			     String passeword="";
     
     
    						try {
     
    							Connection connection = null;
    							String driverName = "oracle.jdbc.driver.OracleDriver";
    							Class.forName(driverName);
                             	String serverName = "10.133.0.25";
    				  			String portNumber = "1521";
    				  			String sid = "fin";
    				  			String url = "jdbc:oracle:thin:@" + serverName + ":" + portNumber +":" + sid;
                                String username = "DEVRTO";
    				  			String password = "DEVRTO";
    							connection = DriverManager.getConnection(url, username, password);
    							Statement instruction = connection.createStatement();
     
    	String sql = "   select utilisateur, mot_passe from utilisateur where utilisateur ='"+nom+"' and mot_passe ='"+passe1+"' ";
    	ResultSet resultat = instruction.executeQuery(sql);
    	HttpServletRequest request = null;
    	HttpSession session = request.getSession(true);
    						     while (resultat.next()){ 	
    						    	 prenom= resultat.getString("utilisateur");
    						    	 passeword= resultat.getString("mot_passe");
    				                    session.setAttribute("uname",prenom);
    				                     session.setAttribute("agence",passeword);
    				               }
     
    						    if ((prenom.equals(nom))&& (passeword.equals(passe1))) {
    						    	menu a =new menu();
    						    	 a.setVisible(true);
    						    	 a.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    								a.setResizable (false);
    						        a.setLocationRelativeTo(null);
    								setVisible(false);
    						     }
    						     else
    						    	  {
    		 JOptionPane ddd1 = new JOptionPane();
    	   ddd1.showMessageDialog(david.this, "mot passe ou user erronée ","Erreur",JOptionPane.INFORMATION_MESSAGE);
     
    							     }
    						}
     
    						 	catch (Exception ex) {
    				          		System.out.println("jjjjjjjjjjj "+ex.getMessage());
     
    								  ex.printStackTrace() ;
    							} 
     
    			       }
    		});
    	}
    	return jButton;
    }
    public static void main(String[] args) {
    	 	SwingUtilities.invokeLater(new Runnable() {
    			public void run() {
    				david thisClass = new david();
    				thisClass.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    				thisClass.setVisible(true);
    				thisClass.setResizable (false);
     
     
    				thisClass.setLocationRelativeTo(null);
    			}
    		});
    	}
     
     
    	public david() {
    		super();
    		initialize();
    	}
     
     
    	private void initialize() {
     
    		 this.setSize(700, 405);
    		this.setBackground(Color.orange);
    		this.setContentPane(getJContentPane());
    		this.setTitle("TRC-EXL-RTO-INF");
    		this.setIconImage(new ImageIcon("src/image/sonatrach.png").getImage());
    		 }
     
    	private JPanel getJContentPane() {
    		if (jContentPane == null) {
    			 jContentPane = new JPanel();
    			jContentPane.setLayout(null);
    			jContentPane.setBackground(new Color(0, 138, 255));
    			jContentPane.add(getJPanel(), null);
     
    		}
    		return jContentPane;
    	}
    }

    message d'erreur
    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
     
    jjjjjjjjjjj null
    java.lang.NullPointerException
    	at david$1.actionPerformed(david.java:118)
    	at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
    	at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
    	at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
    	at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
    	at java.awt.Component.processMouseEvent(Unknown Source)
    	at javax.swing.JComponent.processMouseEvent(Unknown Source)
    	at java.awt.Component.processEvent(Unknown Source)
    	at java.awt.Container.processEvent(Unknown Source)
    	at java.awt.Component.dispatchEventImpl(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
    	at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
    	at java.awt.Container.dispatchEventImpl(Unknown Source)
    	at java.awt.Window.dispatchEventImpl(Unknown Source)
    	at java.awt.Component.dispatchEvent(Unknown Source)
    	at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    	at java.awt.EventQueue.access$000(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.awt.EventQueue$1.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.awt.EventQueue$2.run(Unknown Source)
    	at java.security.AccessController.doPrivileged(Native Method)
    	at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
    	at java.awt.EventQueue.dispatchEvent(Unknown Source)
    	at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    	at java.awt.EventDispatchThread.run(Unknown Source)
    sur la ligne
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    	HttpSession session = request.getSession(true);

    merci

  2. #2
    Membre éclairé
    Homme Profil pro
    Développeur informatique
    Inscrit en
    Avril 2010
    Messages
    394
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur informatique
    Secteur : Distribution

    Informations forums :
    Inscription : Avril 2010
    Messages : 394
    Par défaut
    Bonjour,

    Forcément que tu as une erreur...

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
     
    HttpServletRequest request = null;
    HttpSession session = request.getSession(true);
    Il n'y a pas quelque chose qui te choque ?

    Mako.

  3. #3
    Membre éclairé
    Inscrit en
    Avril 2007
    Messages
    679
    Détails du profil
    Informations forums :
    Inscription : Avril 2007
    Messages : 679
    Par défaut
    oui ça utilise au niveau servlet

    mais comment faire créer une session avec interface windiows

  4. #4
    Membre Expert
    Profil pro
    Inscrit en
    Août 2006
    Messages
    3 276
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Août 2006
    Messages : 3 276
    Par défaut
    Tu cherches à faire quoi exactement ?

  5. #5
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Septembre 2008
    Messages
    1 190
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Septembre 2008
    Messages : 1 190
    Par défaut
    A priori il te faut juste construire une HttpServletRequest.
    Mais tu ne sembles pas très bien gérer les concepts associés, je te conseille donc de relire tes cours!

Discussions similaires

  1. creation une session
    Par ulysse031 dans le forum Servlets/JSP
    Réponses: 1
    Dernier message: 18/04/2011, 13h39
  2. Réponses: 13
    Dernier message: 16/04/2004, 12h00
  3. [debutant][jsp]Passage d'entier avec une session sans cookie
    Par o151181 dans le forum Servlets/JSP
    Réponses: 5
    Dernier message: 04/02/2004, 18h22
  4. Déconnexion d'une session Win2k
    Par lamasse dans le forum C++Builder
    Réponses: 3
    Dernier message: 02/10/2003, 08h39

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