Compte-rendu TP Programmation JAVA
Compte-rendu TP Programmation JAVA
6, bd maréchal Juin
F-14050 Caen cedex 4
Programmation JAVA
Younes EL KHATTAB
Mohamed LAHLOU
2007-2008
Table des matières
[Link]
import [Link].*;
import [Link].*;
try{
s=new ServerSocket(45225);
}catch(IOException e)
{
[Link]("Erreur socket" +e);
[Link](1);
}
while(true)
{
Socket service= [Link]();
l=new lister(service);
[Link]();
}
}
3
try {
flux=new PrintStream([Link](),true);
} catch (IOException e1) {
// TODO Auto-generated catch block
[Link]();
}
try{
File f= new File([Link]());
listning=new String[[Link]().length];
listning=[Link]();
[Link]([Link]);
for(int i=0;i<[Link];i++)
[Link](listning[i]);
}catch(IOException e)
{
[Link](-1);//dans le cas ou l'adresse demandée n'existe
pas
}
}
}
[Link]
import [Link].*;
import [Link].*;
import [Link];
4
1.1.2 Exemple d’exécution
Dans cet exemple, le client cherche à lister le repértoire C: . Après cette requête, le message
affiché dans la console est :
Console :
le nombre d'entrées dans le repertoire est: 26
Les entrées sont:
[Link]
[Link]
[Link]
[Link]
[Link]
[Link]
cmdcons
cmldr
[Link]
5
Documents and Settings
eclipse
[Link]
JBuilder4
JBuilder9
MC7DEMO
[Link]
[Link]
ntldr
ocs-ng
[Link]
Program Files
Qt
RECYCLER
System Volume Information
temp
WINNT
6
1.2 Programmation RMI
[Link]
import [Link].*;
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
7
[Link] :
import [Link].*;
[Link](new [Link]());
try{
InterfaceHeureServeur h = ( InterfaceHeureServeur )
[Link]("rmi://pc31/myObject");
[Link]([Link]());
}catch(Exception e){
[Link]("Exception: "+e);
}
}
}
[Link] Remarques
Nous avons compilé client et serveur dans 2 répertoires différents, en conséquence, le client
n’as pas pu trouvé le _Stub.class et _Skel.class . Nous avons dû les déplacer dans le serveur
(public_html) et ajouter le port 80 dans le fichier .policy et indiquer l’adresse url au client lors de
l’exécution pour les trouver.
8
1.2.2 Développement d’un logiciel de discussion
Dans cette partie, il s’agit de développer un logiciel de discussion en direct en utilisant les RMI.
L’interface utilisateur est réalisé avec le plugin ‘‘jigloo’’.
[Link] JAVADOC
Class ChatServeur
[Link]
[Link]
[Link]
[Link]
ChatServeur
All Implemented Interfaces:
InterfaceChatServeur, [Link], [Link]
Constructor Summary
ChatServeur()
Method Summary
void broadcastMessage(Message msg)
This method send a message entered as an argument to all connected
clients.
[Link] connect([Link] pseudo, [Link] url)
adds the pseudo and URL entered as an argument into the set clients.
void disconnect([Link] pseudo)
Remove the client from the set.
[Link] getCalendar()
return a Calendar object to indicate the server's time.
static void main([Link][] args)
9
Methods inherited from class [Link]
clone, exportObject, exportObject, exportObject, unexportObject
Constructor Detail
ChatServeur
public ChatServeur()
throws [Link]
Throws:
[Link]
Method Detail
getCalendar
public [Link] getCalendar()
throws [Link]
Description copied from interface: InterfaceChatServeur
return a Calendar object to indicate the server's time.
Specified by:
getCalendar in interface InterfaceChatServeur
Returns:
Calendar.
Throws:
[Link]
connect
public [Link] connect([Link] pseudo,
[Link] url)
throws [Link]
Description copied from interface: InterfaceChatServeur
adds the pseudo and URL entered as an argument into the set clients.
Specified by:
connect in interface InterfaceChatServeur
Returns:
String specify if the clients is added or not, and why not if is the.
Throws:
10
[Link]
disconnect
public void disconnect([Link] pseudo)
throws [Link]
Description copied from interface: InterfaceChatServeur
Remove the client from the set.
Specified by:
disconnect in interface InterfaceChatServeur
Throws:
[Link]
broadcastMessage
public void broadcastMessage(Message msg)
throws [Link]
Description copied from interface: InterfaceChatServeur
This method send a message entered as an argument to all connected clients.
Specified by:
broadcastMessage in interface InterfaceChatServeur
Parameters:
msg - Message to be sent.
Throws:
[Link]
main
public static void main([Link][] args)
11
Package Class Use Tree Deprecated Index Help
PREV CLASS NEXT CLASS FRAMES NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD
Class ChatClient
[Link]
[Link]
[Link]
[Link]
ChatClient
All Implemented Interfaces:
InterfaceChatClient, [Link], [Link]
Method Summary
void connexion([Link] nickName, ChatClient b)
void deconexion()
12
Methods inherited from class [Link]
equals, getRef, hashCode, toString, toStub
Method Detail
diffuseMessage
public void diffuseMessage(Message msg)
throws [Link]
Description copied from interface: InterfaceChatClient
display the message entered as an argument.
Specified by:
diffuseMessage in interface InterfaceChatClient
Throws:
[Link]
connexion
public void connexion([Link] nickName,
ChatClient b)
throws [Link],
[Link],
[Link]
Throws:
[Link]
[Link]
[Link]
deconexion
public void deconexion()
throws [Link],
[Link],
[Link]
Throws:
[Link]
[Link]
[Link]
sendMsg
public void sendMsg([Link] Msg)
throws [Link],
[Link],
[Link]
Throws:
[Link]
[Link]
[Link]
getCalendar
public [Link] getCalendar()
13
throws [Link]
Throws:
[Link]
main
public static void main([Link][] args)
14
[Link] Code Java
[Link]
import [Link];
[Link]
public class EnsConnect {
private int nbConnect;
private String pseudo[];
private String url[];
private int maxConnect;
/**
* Create a set of clients.
* @param maxConnect, the set's maximal size.
*/
public EnsConnect(int maxConnect){
[Link]=maxConnect;
[Link]=0;
pseudo=new String[maxConnect];
url=new String[maxConnect];
}
/**
* Adds a client to the set.
* @param pseudo
* @param url
* @return -1 if the pseudo is already exist.
* 0 if the number of clients is maximal.
* 1 if the client is added.
*/
public int addConnect(String pseudo, String url)
{
for(int i=0;i<nbConnect;i++){
if([Link][i].compareToIgnoreCase(pseudo)==0)
return -1;
}
if(nbConnect==maxConnect)
15
return 0;
{
[Link][nbConnect]=pseudo;
[Link][nbConnect]=url;
nbConnect++;
return 1;
}
}
/**
* Remove the client specified in the argument from the set.
* @param pseudo
*/
public void subConnect(String pseudo)
{
for(int i=0;i<nbConnect;i++)
if([Link]([Link][i])==0)
{
[Link][i]=[Link][nbConnect-1];
[Link][i]=[Link][nbConnect-1];
nbConnect--;
}
}
/**
* Return the number of clients.
* @return the number of clients.
*/
public int getNbConnect(){return [Link];}
/**
* Return the URL of client.
* @param i, the index of client.
* @return the URL of client.
*/
public String getConnectUrl(int i){return url[i];}
/**
* Return the pseudo of client.
* @param i, the index of client.
* @return the Pseudo of client.
*/
public String getConnectPseudo(int i){return pseudo[i];}
}
[Link]
import [Link].*;
import [Link];
import [Link];
/**
* This interface used to expose the server and look up for the client.
* @author khattab
*/
/**
* adds the pseudo and URL entered as an argument into the set clients.
16
* @param pseudo
* @param url
* @return String specify if the clients is added or not, and why not if is
the.
* @throws RemoteException
*/
public String connect(String pseudo, String url) throws RemoteException;
/**
* Remove the client from the set.
* @param pseudo
* @throws RemoteException
*/
public void disconnect(String pseudo) throws RemoteException;
/**
* This method send a message entered as an argument to all connected
clients.
* @param msg Message to be sent.
* @throws RemoteException
*/
public void broadcastMessage(Message msg) throws RemoteException;
/**
* return a Calendar object to indicate the server's time.
* @return Calendar.
* @throws RemoteException
*/
[Link]
import [Link].*;
import [Link].*;
import [Link].*;
import [Link].*;
import [Link];
import [Link];
/**
* This class used to expose the server and look up for the client.
* @author khattab
*/
17
if(etat==-1)
return "Ce pseudo est deja connecté, veuillez vous
connecter avec un auter pseudo";
if(etat==0)
return "Le chat Romm est pleine. Veuillez vous reconnecter
ultérieurement";
return "Connecxion établie";
}
[Link]
import [Link];
import [Link];
/**
*
* This interface used to expose the client and look up for the server.
* @author khattab
*/
public interface InterfaceChatClient extends Remote{
/**
* display the message entered as an argument.
*
* @param msg.
* @throws RemoteException
*/
public void diffuseMessage(Message msg) throws RemoteException;
}
18
[Link]
import [Link].*;
import [Link];
import [Link];
import [Link].*;
import [Link];
/**
*
* This class used to expose the client and look up for the server.
* @author khattab
*/
19
public Calendar getCalendar() throws RemoteException{
if(etatConnexion==1)
return [Link]();
return null;
}
url=args[0];
Time t;
[Link](new [Link]());
try {
ChatClient b=new ChatClient();
t=new Time(b);
[Link]();
} catch (RemoteException e1) {
// TODO Auto-generated catch block
[Link]();
}
}
}
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit [Link] for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Display extends [Link] {
{
try {
[Link]([Link]
SystemLookAndFeelClassName());
} catch(Exception e) {
20
[Link]();
}
}
private JTextPane P;
private JTextPane time1;
private JTextPane time2;
private JButton Connect;
private JButton disConnect;
private JTextArea Msg;
private JTextField Saisie;
private JTextPane TimeServeur;
private JTextPane TimeClient;
private JTextField Pseudo;
private ChatClient b;
21
[Link](1);
}
[Link](e);
[Link](0);
}
}
);
{
P = new JTextPane();
getContentPane().add(P);
[Link]("Pseudo");
[Link](12, 7, 66, 27);
[Link](false);
[Link](false);
}
{
Pseudo = new JTextField();
getContentPane().add(Pseudo);
[Link](76, 7, 123, 27);
}
{
time1 = new JTextPane();
getContentPane().add(time1);
[Link]("Heure Client");
[Link](339, 11, 84, 27);
[Link](false);
[Link](false);
}
{
TimeClient = new JTextPane();
getContentPane().add(TimeClient);
[Link](416, 10, 71, 27);
[Link](false);
[Link](false);
}
{
time2 = new JTextPane();
getContentPane().add(time2);
[Link]("Heure Serveur");
[Link](508, 11, 101, 27);
[Link](false);
[Link](false);
}
{
TimeServeur = new JTextPane();
getContentPane().add(TimeServeur);
[Link](619, 11, 63, 22);
[Link](false);
[Link](false);
}
{
Saisie = new JTextField();
[Link](0, 390, 714, 33);
getContentPane().add(Saisie);
}
{
Msg = new JTextArea();
[Link](0, 49, 714, 330);
[Link](false);
getContentPane().add(Msg);
}
22
{
Connect = new JButton();
getContentPane().add(Connect);
[Link]("Connexion");
[Link](205, 7, 113, 27);
}
{
disConnect = new JButton();
getContentPane().add(disConnect);
[Link]("Deconexion");
[Link](205, 7, 113, 27);
[Link](false);
}
gestionEvent gestionnaire =new gestionEvent();
[Link](gestionnaire);
[Link](gestionnaire);
[Link](gestionnaire);
pack();
[Link](730, 489);
} catch (Exception e) {
[Link]();
}
}
23
private class gestionEvent implements ActionListener{
public void actionPerformed (ActionEvent e){
if([Link]()==Connect){
Connexion([Link]());
[Link](false);
[Link](true);
}
if([Link]()==Saisie){
SaisieMsg([Link]());
[Link]("");
}
if([Link]()==disConnect){
Deconexion();
[Link]("");
[Link](false);
[Link](true);
[Link]("");
}
}
}
[Link]
import [Link];
import [Link].*;
public Time(ChatClient b) {
this.b=b;
}
public void run(){
while(true){
cClient=[Link]();
[Link]([Link](Calendar.HOUR_OF_DAY),
[Link]([Link]), [Link]([Link]));
try {
cServer=[Link]();
if(cServer!=null)
[Link]([Link](Calendar.HOUR_OF_DAY),
[Link]([Link]), [Link]([Link]));
} catch (RemoteException e1){}
try {
[Link]().sleep(1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
[Link]();
}
}
}
}
24
[Link] Exemple d’exécution
25
2 TP2 :JavaBeans
Dans cet exercice, on va présenter que la version finale du bean, puisque c’est cette dernière qui
contient le maximum de propriétés. Vous trouverez les autres beans dans le CD accompagné avec ce
compte-rendu.
[Link]
import [Link].*;
import [Link].*;
if([Link]()==true){
if([Link]("jpg") || [Link]("gif")){
return true;
}
return false;
}
return false;
}
public BeanAffichage2()
{
numImg = 0;
dirName = "C:/images/";
boucle=false;
diapo=false;
wait=3;
f = new Filter();
26
if([Link] != 0)
{
imgs = new Image [[Link]];
for(int i=0; i<[Link]; ++i)
imgs[i] =
[Link]().getImage(dirName+files[i]);
}
}
}
if([Link] != 0)
{
imgs = new Image [[Link]];
for(int i=0; i<[Link]; ++i)
imgs[i] =
[Link]().getImage(dirName+files[i]);
}
}
}
27
}
public Dimension getPreferredSize()
{
return new Dimension(largeur,longueur);
}
}
}
[Link]
import [Link].*;
import [Link];
import [Link].*;
private Calendar c;
public BeanHeure(){
upDate();
}
28
[Link]
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit [Link] for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class TestBean extends [Link] {
private BeanAffichage2 defileImage;
private JButton Premier;
private JTextPane text;
private BeanHeure Heure;
private JTextField Directory;
private JTextPane textdir;
private JTextField tempo;
private JRadioButton diapo;
private JRadioButton boucle;
private JButton Dernier;
private JButton Precedent;
private JButton Suivant;
29
Thread d=new Thread(defileImage);
[Link]();
}
{
Suivant = new JButton();
getContentPane().add(Suivant);
[Link]("Suivant");
[Link](21, 159, 115, 39);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]();
}
});
}
{
Premier = new JButton();
getContentPane().add(Premier);
[Link]("Premier");
[Link](21, 217, 115, 37);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]();
}
});
}
{
Precedent = new JButton();
getContentPane().add(Precedent);
[Link]("Precedent");
[Link](168, 159, 115, 39);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]();
}
});
}
{
Dernier = new JButton();
getContentPane().add(Dernier);
[Link]("Dernier");
[Link](168, 217, 115, 37);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]();
}
});
}
{
boucle = new JRadioButton();
getContentPane().add(boucle);
[Link]("Boucle");
[Link](21, 271, 110, 30);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]([Link]());
}
});
}
{
diapo = new JRadioButton();
getContentPane().add(diapo);
30
[Link]("Diaporama");
[Link](21, 308, 115, 30);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]([Link]());
}
});
}
{
tempo = new JTextField();
getContentPane().add(tempo);
[Link](121, 345, 68, 31);
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link](new
Integer([Link]()));
}
});
}
{
text = new JTextPane();
getContentPane().add(text);
[Link]("Temporisation:");
[Link](21, 347, 115, 29);
[Link](false);
[Link](new [Link]("Segoe UI",1,12));
[Link](false);
}
{
textdir = new JTextPane();
getContentPane().add(textdir);
[Link]("Nom répertoire :");
[Link](21, 17, 130, 32);
[Link](new [Link]("Segoe UI",1,12));
[Link](false);
[Link](false);
}
{
Directory = new JTextField();
getContentPane().add(Directory);
[Link](135, 17, 392, 32);
[Link]("C:/images/");
[Link](new ActionListener() {
public void actionPerformed(ActionEvent evt) {
[Link]([Link]());
[Link]();
}
});
}
{
Heure = new BeanHeure();
getContentPane().add(Heure);
[Link](568, 21, 55, 23);
}
pack();
[Link](725, 462);
} catch (Exception e) {
[Link]();
}
}
}
31
2.2 Exemple d’exécusion
32
33
3 TP3 : Interaction Java-Base de données
3.1 Première partie :
On souhaite ici, dans un premier temps, développer une application pour l’interrogation de base
de données cinema.
3.1.1 JAVADOC
[Link]
Class GestionBase
[Link]
[Link]
Constructor Summary
GestionBase([Link] comedien)
Contructor, make connextiopn with the data base.
Method Summary
Resultat getListMovies()
Return a comedien movies.
Constructor Detail
GestionBase
public GestionBase([Link] comedien)
Contructor, make connextiopn with the data base.
Parameters:
comedien -
34
Method Detail
getListMovies
public Resultat getListMovies()
Return a comedien movies.
Returns:
Resultat
See Also:
Resultat
[Link]
Class Resultat
[Link]
[Link]
Constructor Summary
Resultat()
Contructor: initiate the Reusultat statut and size.
Method Summary
void addItem([Link] chaine)
Adds data to a data wich had been found before.
[Link]<[Link]> getDonnees()
Return a list of data.
[Link] getItem(int i)
Return the Data indexed by i.
[Link] getNomComedien()
Return the name of comedien.
35
int getSize()
return the number of found data.
int getStatut()
Return the request SQL statut.
void setNomComedien([Link] nom)
Set the Comedien name.
void setStatut(int s)
Set the request SQL statut.
Constructor Detail
Resultat
public Resultat()
Contructor: initiate the Reusultat statut and size.
Method Detail
addItem
public void addItem([Link] chaine)
Adds data to a data wich had been found before.
Parameters:
chaine -
getDonnees
public [Link]<[Link]> getDonnees()
Return a list of data.
Returns:
getItem
public [Link] getItem(int i)
Return the Data indexed by i.
Parameters:
i, - index.
Returns:
data indexed by i.
getNomComedien
public [Link] getNomComedien()
Return the name of comedien.
Returns:
name of comedien.
getSize
public int getSize()
return the number of found data.
Returns:
36
getStatut
public int getStatut()
Return the request SQL statut.
Returns:
setNomComedien
public void setNomComedien([Link] nom)
Set the Comedien name.
Parameters:
nom - comedien name.
setStatut
public void setStatut(int s)
Set the request SQL statut.
Parameters:
estate. -
37
3.1.2 CODE JAVA
[Link]
package [Link];
import [Link].*;
/**
* this class is used to save data returned when the data base has been
interrogated.
* @author khattab
*
*/
public class Resultat {
/**
* Contructor: initiate the Reusultat statut and size.
*
*/
public Resultat(){
statut=0;
size=0;
}
/**
* Adds data to a data wich had been found before.
* @param chaine
*/
/**
* Return a list of data.
* @return
*/
38
* Return the name of comedien.
* @return name of comedien.
*/
public String getNomComedien(){
return Comedien;
}
/**
* return the number of found data.
* @return
*/
/**
* Return the request SQL statut.
* @return
*/
public int getStatut(){
return statut;
}
/**
* Set the Comedien name.
* @param nom comedien name.
*/
public void setNomComedien(String nom){
Comedien=nom;
}
/**
* Set the request SQL statut.
* @param estate.
*/
public void setStatut(int s){
statut=s;
}
}
[Link]
package [Link];
import [Link].*;
import [Link].*;
class Connect{
private Connection Conn;
private final String NomBase;
public Connect(){
try{
[Link]("[Link]").newInstance();
}catch(Exception e1){
[Link]("Impossible de charger le driver "+
[Link]());
[Link](1);
}
NomBase="jdbc:postgresql://[Link]/cinema?user=khattab&
39
password=********";
try{
Conn=[Link](NomBase);
}catch(SQLException e2){
[Link]("Erreur de connexion "+ [Link]());
[Link](1);
}
}
public Connection getConn(){return Conn;}
}
/**
* This class is used to interogate the dada base cinema.
* @author khattab
*
*/
try {
Statement stmt=[Link]();
[Link](1);
int i=0;
ResultSet rs=[Link]("select identc from com
where LOWER([Link]) like LOWER('"+comedien+"%')");
while([Link]())
{
i++;
nomComedien=[Link]("identc");
}
if(i==1){
rs=[Link]("select titre from
film,role,com
where LOWER([Link]) like LOWER('"+comedien+"%') and [Link]=[Link] and
[Link]=[Link]");
while([Link]())
[Link]([Link]("titre"));
[Link](nomComedien);
}
else if(i==0)
[Link](-1);
else if(i>1)
[Link](2);
[Link]();
} catch (SQLException e) {
[Link]("Erreur de Statement "+e);
}
}
40
/**
* Return a comedien movies.
* @return Resultat
* @see Resultat
*/
return result;
}
}
[Link]
package [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit [Link] for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class Cinema extends [Link] {
{
//Set Look & Feel
try {
[Link]("[Link].
WindowsLookAndFeel");
} catch(Exception e) {
[Link]();
}
}
41
private JButton OK;
private JButton Sortir;
private JScrollPane MyScroll;
private JScrollPane jScrollPane1;
private JTextArea Resultat;
private JTextPane requeteStatut;
private JTextPane requete;
private JTextPane Titres;
private JTextPane comedien;
private JButton Erase;
/**
* Auto-generated main method to display this JFrame
*/
public static void main(String[] args) {
Cinema inst = new Cinema();
[Link](true);
}
public Cinema() {
super("Base de données cinématographique");
initGUI();
}
42
{
MyScroll = new JScrollPane();
getContentPane().add(MyScroll);
[Link](105, 82, 427, 130);
{
Resultat = new JTextArea();
[Link](Resultat);
[Link](false);
}
}
{
comedien = new JTextPane();
getContentPane().add(comedien);
[Link]("Nom Comedien:");
[Link](8, 42, 97, 28);
[Link](false);
[Link](false);
}
{
Titres = new JTextPane();
getContentPane().add(Titres);
[Link]("Titres films:");
[Link](12, 82, 87, 25);
[Link](false);
[Link](false);
}
{
requete = new JTextPane();
getContentPane().add(requete);
[Link]("Statut requête");
[Link](38, 224, 114, 29);
[Link](false);
[Link](false);
}
{
requeteStatut = new JTextPane();
getContentPane().add(requeteStatut);
[Link](126, 224, 161, 28);
[Link](false);
[Link](false);
}
gestionEvent gestionnaire =new gestionEvent();
[Link](gestionnaire);
[Link](gestionnaire);
[Link](gestionnaire);
[Link](gestionnaire);
pack();
[Link](575, 335);
} catch (Exception e) {
[Link]();
}
}
private class gestionEvent implements ActionListener{
Resultat result;
GestionBase T=null;
public void actionPerformed (ActionEvent e){
if([Link]()==Erase){
[Link]("");
[Link]("");
}
if([Link]()==Sortir)
43
[Link](1);
if([Link]()==OK || [Link]()==Com){
T=new GestionBase([Link]());
result=[Link]();
[Link]("");
switch([Link]())
{
case -1:
[Link]("Pas de Comedien");
break;
case 0:
[Link]("Pas de Connexion");
break;
case 1:
[Link]("OK");
[Link]([Link]());
for(int i=0;i<[Link]();i++)
[Link]([Link](i)+"\n");
break;
case 2:
[Link]("Trop de comedien");
break;
}
}
}
}
44
3.1.3 Exemple D’exécusion :
45
3.2 Deuxième partie
Dans cette partie, on veut réutiliser les classes GestionBase et Resultat qui sont dans le fichier
d’archive [Link]. On developpe une servelet qui interroge la base de données via [Link].
Finalement la base de données sera intérroger via un navigateur.
[Link]
import [Link];
import [Link].*;
import [Link];
import [Link];
import [Link];
import [Link];
import [Link];
/**
* Servlet implementation class for Servlet: Comedien
*
*/
public class Comedien extends [Link] implements
[Link] {
/* (non-Java-doc)
* @see [Link]#HttpServlet()
*/
private static final String CONTENT_TYPE = "text/html";
private Resultat result;
private GestionBase T=null;
PrintWriter out;
public Comedien() {
super();
}
/* (non-Java-doc)
* @see [Link]#doGet(HttpServletRequest request,
HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse
response) throws ServletException, IOException {
T=new GestionBase([Link]("nomc"));
result=[Link]();
switch([Link]())
{
case -1:
[Link](CONTENT_TYPE);
out = [Link]();
[Link]("<p> Pas de Comedien </p>");
break;
case 0:
[Link](CONTENT_TYPE);
out = [Link]();
[Link]("<p> Pas de Connexion </p>");
46
break;
case 1:
[Link](CONTENT_TYPE);
out=[Link]();
[Link]("<p>Comedien: "+[Link]()+"</p>");
for(int i=0;i<[Link]();i++)
[Link]("<p>"+[Link](i)+"</p>");
break;
case 2:
[Link](CONTENT_TYPE);
out = [Link]();
[Link]("<p> Trop de comedien </p>");
break;
}
}
}
[Link]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>TP Servelet</title>
</head>
<body>
<form action="[Link]
Nom Comedien:
<input type=text name=nomc>
<input type=submit value="ok">
</form>
</body>
</html>
47
3.2.2 Exemple d’exécusion
48
4 TP4 : Programmation JSP
4.1 Exercice 1
L’objectif est de trouver un nombre entre 1 et 100 choisi aléatoirement. Le choix aléatoire de ce
nombre sera effectué dans un javabean et l’interface d’interaction avec l’utilisateur et l’utilisateur sera
dans une page jsp.
4.1.1 JAVADOC :
myPackage
Class GuessBean
[Link]
[Link]
All Implemented Interfaces:
[Link]
Constructor Summary
GuessBean()
Method Summary
[Link] getHint()
This method return a String that contain information of guess.
int getNumGuess()
Return the number of guess.
boolean getSucces()
Return true if the guess is true.
void reset()
Reset GuessBean object.
void setGuess(int guess)
Set the Guess and increment the Guess's number.
49
Methods inherited from class [Link]
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
GuessBean
public GuessBean()
Method Detail
reset
public void reset()
Reset GuessBean object.
setGuess
public void setGuess(int guess)
Set the Guess and increment the Guess's number.
Parameters:
guess -
getNumGuess
public int getNumGuess()
Return the number of guess.
Returns:
the guess's number.
getHint
public [Link] getHint()
This method return a String that contain information of guess.
Returns:
Information if the guess is lower or higher or equal than the real number.
getSucces
public boolean getSucces()
Return true if the guess is true. False in otherwise.
Returns:
True if the guess is true. False is the guess is wrong.
50
4.1.2 Code JAVA
[Link]
package myPackage;
import [Link].*;
public GuessBean(){
number=[Link](99)+1;
succes=false;
guess=-1;
numGuess=0;
hint="";
}
/**
* Reset GuessBean object.
* @return void
*/
public void reset(){
succes=false;
number=[Link](99)+1;
guess=-1;
numGuess=0;
hint="";
}
/**
* Set the Guess and increment the Guess's number.
* @param guess
*/
public void setGuess(int guess){
[Link]=guess;
numGuess++;
if([Link]==number){
succes=true;
hint="nombre exact";
}
else
if([Link]>number){
hint="nombre trop grand";
}
else
hint="nombre trop petit";
}
/**
* Return the number of guess.
* @return the guess's number.
*/
public int getNumGuess(){
return numGuess;
51
}
/**
* This method returns a String that contain information of guess.
* @return Information if the guess is lower or higher or equal than the
real number.
*/
public String getHint(){
return hint;
}
/**
* Return true if the guess is true. False in otherwise.
* @return True if the guess is true. False is the guess is wrong.
*/
public boolean getSucces(){
return succes;
}
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<h1>Deviner un nombre</h1>
<%if([Link]()==0){%>
<p>Bienvenue au jeu "Deviner un nombre"<br/>
J'ai choisie un nombre entre 1 et 100<br/><br/><br/>
Choisissez un nombre:</p>
<%}else {if([Link]()==false){%>
Non, Desole, essayer encore. Conseil: <%=[Link]()%><br/>
Vous etes a <%=[Link]()%> essai(s)<br/>
<%} else {%>
Felicitation, Vous l'avez trouvez en <%=[Link]()%> essai(s)<br/>
<%
[Link]();}} %>
<FORM action="[Link]">
<INPUT TYPE="Text" NAME="guess" />
<INPUT TYPE="Submit" value="Soumettre"/>
</FORM>
</body>
</html>
52
4.1.3 Exemple d’exécution
53
4.2 Exercice 2
Cet exercice consiste à développer une interface permettant aux utilisateurs de s’inscrire dans
une base de données (Ici on a crée une table « chat » dans la base de données cinema). Ensuite, les
utilisateurs peuvent se connectés en indiquant leur pseudo et leur mot de passe. Aussi ils peuvent
récupérer leur mot de passe via Javamail en indiquant leur pseudo.
4.2.1 JAVADOC
myPackage
Class IrcBean
[Link]
[Link]
All Implemented Interfaces:
[Link]
Constructor Summary
IrcBean()
Method Summary
boolean addLogin([Link] nickName, [Link] password,
[Link] firstName, [Link] lastName,
[Link] email, [Link] url)
This method adds new user in the database.
boolean connect([Link] nickName, [Link] password)
Return true if the nickName and password entered are matched with the
nickName and password saved in database.
[Link] getInfo([Link] nickName)
Return user's info.
54
[Link] getPassWord([Link] Pseudo)
Return the user's password.
[Link] getProfile([Link] nickName)
Return user's profile.
Constructor Detail
IrcBean
public IrcBean()
Method Detail
connect
public boolean connect([Link] nickName,
[Link] password)
Return true if the nickName and password entered are matched with the nickName and
password saved in database. Return false if the nickNAme is not existe or the password is not
correct.
Parameters:
nickName -
password -
Returns:
true if the nickName and password entered are matched with the real nickName and password.
getInfo
public [Link] getInfo([Link] nickName)
Return user's info. To simplify, here the info is the user's email.
Parameters:
nickName -
Returns:
user's info.
getProfile
public [Link] getProfile([Link] nickName)
Return user's profile. Here the profile is the url picture
Parameters:
nickName -
Returns:
user's profile.
addLogin
public boolean addLogin([Link] nickName,
[Link] password,
[Link] firstName,
[Link] lastName,
[Link] email,
55
[Link] url)
This method adds new user in the database.
Parameters:
nickName -
password -
firstName -
lastName -
email -
url -
Returns:
true if the new user is added, false if there is a problem.
getPassWord
public [Link] getPassWord([Link] Pseudo)
Return the user's password.
Parameters:
Pseudo -
Returns:
password.
56
4.2.2 CODE JAVA
[Link]
package myPackage;
import [Link].*;
import [Link].*;
/**
* This javabean is used to get or insert some informations from de database chat.
* @author khattab
*
*/
public IrcBean(){
try{
[Link]("[Link]").newInstance();
}catch(Exception e1){
[Link]("Impossible de charger le driver "+
[Link]());
[Link](1);
}
String
NomBase="jdbc:postgresql://[Link]/cinema?user=khattab&
password=********";
try{
Conn=[Link](NomBase);
}catch(SQLException e2){
[Link]("Erreur de connexion "+ [Link]());
[Link](1);
}
}
/**
* Return true if the nickName and password entered are matched with the nickName
and password saved in database.
* Return false if the nickNAme is not existe or the password is not correct.
* @param nickName
* @param password
* @return true if the nickName and password entered are matched with the real
nickName and password.
* @return false if the nickNAme is not existe or the password is not correct.
*/
public boolean connect(String nickName, String password){
try {
Statement stmt=[Link]();
ResultSet rs=[Link]("select password from chat where
nickName='"+nickName+"'");
while([Link]()){
if([Link]([Link]("password"))==0)
return true;
}
return false;
57
}
catch(SQLException e) {
[Link]("Erreur de Statement "+e);
}
return false;
}
/**
* Return user's info. To simplify, here the info is the user's email.
* @param nickName
* @return user's info.
*/
/**
* Return user's profile. Here the profile is the url picture
* @param nickName
* @return user's profile.
*/
/**
* This method adds new user in the database.
* @param nickName
* @param password
* @param firstName
* @param lastName
* @param email
58
* @param url
* @return true if the new user is added, false if there is a problem.
*/
59
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method=post action="[Link]">
<center>
<table cellpadding=4 cellspacing=2 border=0>
<th bgcolor="#CCCCFF" colspan=2>
<font size=5>Welcome on JAVChat </font>
<br>
</th>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=1>
<b>NickName</b>
<br>
<input type="text" name="nickName" size=10 value="" maxlength=10>
</td>
<td valign=top>
<b>Password</b>
<br>
<input type="password" name="password" size=10 value="" maxlength=10></td>
<br>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<a href=[Link]>Register</a>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<a href="[Link]">Forgot your password<a>
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
60
[Link]
<!--
(c) dp 04/02
<%if([Link](pseudo,passWord)==false){%>
<META http-equiv="refresh" content="0;
URL=[Link]
<%}else{
String info=[Link](pseudo);
String profile=[Link](pseudo);
%>
<HTML>
<SCRIPT language=javascript>
function openWaitingWindow()
{
WaitingWindow = [Link]
('[Link] ;
}
function closeWaitingWindow ()
{
[Link] () ;
}
openWaitingWindow () ;
</SCRIPT>
<APPLET CODE="[Link]"
NAME="JAVirc"
CODEBASE="[Link]
ARCHIVE="[Link]"
WIDTH=100%
HEIGHT=80%
MAYSCRIPT>
<PARAM NAME=cabbase VALUE="[Link]">
<PARAM NAME=server VALUE="[Link]">
<PARAM NAME=port VALUE=7000>
61
<PARAM NAME=IRCName VALUE=<%=info %>>
62
<PARAM NAME=ColorListForeground VALUE="000000">
<PARAM NAME=ColorBackgroundDisplayQuery VALUE="c0c0ff">
<PARAM NAME=ColorBackgroundScrollbarQuery VALUE="c0c0c0">
<PARAM NAME=ColorForegroundScrollbarQuery VALUE="c0c0c0">
<PARAM NAME=ColorBackgroundTextfieldQuery VALUE="c0c0ff">
<PARAM NAME=ColorForegroundTextfieldQuery VALUE="000000">
<PARAM NAME=ColorToolbarQueryBackground VALUE="c0c0ff">
<PARAM NAME=ColorChoiceQueryBackground VALUE="c0c0ff">
<PARAM NAME=ColorChoiceQueryForeground VALUE="000000">
<PARAM NAME=ColorButtonsQueryBackground VALUE="c0c0ff">
<PARAM NAME=ColorButtonsQueryForeground VALUE="000000">
<PARAM NAME=ColorPrivateMessage VALUE="000000">
<PARAM NAME=ColorPublicMessage VALUE="000000">
<PARAM NAME=ColorSystem VALUE="000000">
<PARAM NAME=ColorInvite VALUE="006400">
<PARAM NAME=ColorQuit VALUE="ff0000">
<PARAM NAME=ColorChannelMessage VALUE="006400">
<PARAM NAME=ColorWallops VALUE="ff0000">
<PARAM NAME=ColorNickChange VALUE="006400">
<PARAM NAME=ColorTopicChange VALUE="006400">
<PARAM NAME=ColorShowTopic VALUE="006400">
<PARAM NAME=ColorCtcp VALUE="ff0000">
<PARAM NAME=ColorJoinChannel VALUE="006400">
<PARAM NAME=ColorNotice VALUE="ff0000">
<PARAM NAME=ColorAction VALUE="ff0fed">
<PARAM NAME=ColorBroadcastMessage VALUE="ff0000">
<PARAM NAME=Smiley VALUE="yes">
<PARAM NAME=Smiley0 VALUE="[Link]|:)|yes">
<PARAM NAME=Smiley1 VALUE="[Link]|:d|yes">
<PARAM NAME=Smiley2 VALUE="[Link]|:p|yes">
<PARAM NAME=Smiley3 VALUE="[Link]|;)|yes">
<PARAM NAME=Smiley4 VALUE="[Link]|:(|yes">
<PARAM NAME=Smiley5 VALUE="[Link]|(y)|yes">
<PARAM NAME=Smiley6 VALUE="[Link]|(n)|yes">
<PARAM NAME=Smiley7 VALUE="[Link]|(l)|yes">
<PARAM NAME=Smiley8 VALUE="[Link]|(u)|yes">
<PARAM NAME=Smiley9 VALUE="[Link]|(p)|no">
<PARAM NAME=Smiley10 VALUE="[Link]|(b)|no">
<PARAM NAME=Smiley11 VALUE="[Link]|(d)|no">
<PARAM NAME=Smiley12 VALUE="[Link]|(t)|no">
<PARAM NAME=Smiley13 VALUE="[Link]|(@)|no">
<PARAM NAME=Smiley14 VALUE="[Link]|(c)|no">
<PARAM NAME=Smiley15 VALUE="n_bulb.gif|(i)|no">
<PARAM NAME=Smiley16 VALUE="[Link]|(s)|no">
<PARAM NAME=Smiley17 VALUE="[Link]|(h)|no">
<PARAM NAME=Smiley18 VALUE="[Link]|(*)|no">
<PARAM NAME=Smiley19 VALUE="[Link]|(e)|no">
<PARAM NAME=Smiley20 VALUE="[Link]|(8)|no">
<PARAM NAME=Smiley21 VALUE="[Link]|(m)|no">
<PARAM NAME=Smiley22 VALUE="[Link]|(f)|yes">
<PARAM NAME=Smiley23 VALUE="[Link]|(z)|no">
<PARAM NAME=Smiley24 VALUE="[Link]|(k)|no">
<PARAM NAME=Smiley25 VALUE="[Link]|(g)|no">
<PARAM NAME=Smiley26 VALUE="[Link]|(x)|no">
<PARAM NAME=MircColors VALUE="yes">
<PARAM NAME=Toolbar Value="yes">
<PARAM NAME=EnableURL VALUE="yes">
<PARAM NAME=EnableNick VALUE="yes">
<PARAM NAME=Channels VALUE="#help;#aide;#france;#caen">
<PARAM NAME=Actions VALUE="applauds;hugs %;kisses % strongly">
<PARAM NAME=ChannelOperator VALUE="no">
63
<PARAM NAME=ProfilURL VALUE=<%=profile %>>
<PARAM NAME=ColorTabbedPaneBackground VALUE="f0f0ff">
<PARAM NAME=ColorTabbedPaneUsed VALUE="ff0000">
<PARAM NAME=ColorTabbedText VALUE="000000">
<PARAM NAME=ColorTabbedActiveText VALUE="0000ff">
<PARAM NAME=ColorBackgroundTopic VALUE="f0f0ff">
<PARAM NAME=ColorForegroundTopic VALUE="000000">
<PARAM NAME=ColorBackgroundCloseChannelButton VALUE="f0f0ff">
<PARAM NAME=ColorForegroundCloseChannelButton VALUE="000000">
<PARAM NAME=NickLength VALUE=9>
<PARAM NAME=StatusFamilyFont VALUE="SansSerif">
<PARAM NAME=StatusStyleFont VALUE="Plain">
<PARAM NAME=StatusSizeFont VALUE="12">
<PARAM NAME=StatusLineSpacing VALUE="16">
<PARAM NAME=ChannelLineSpacing VALUE="16">
<PARAM NAME=QueryLineSpacing VALUE="16">
<PARAM NAME=ListChannelsFamilyFont VALUE="SansSerif">
<PARAM NAME=ListChannelsStyleFont VALUE="Italic">
<PARAM NAME=ListChannelsSizeFont VALUE="20">
<PARAM NAME=ColorListStatusBackground VALUE="f0f0ff">
<PARAM NAME=ColorListStatusForeground VALUE="000000">
<PARAM NAME=ColorListCloseBackground VALUE="f0f0ff">
<PARAM NAME=ColorListCLoseForeground VALUE="000000">
<PARAM NAME=EnableChannel VALUE="yes">
<PARAM NAME="AllowQuery" VALUE="yes">
<PARAM NAME="Encode" VALUE="8859_1">
</APPLET>
</HTML>
<%}%>
[Link]
<html>
<body>
<form action="[Link]" method=post>
<center>
<table cellpadding=4 cellspacing=2 border=0>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>NickName<sup>*</sup></b>
<br>
<input type="text" name="nickName" size=10 value="" maxlength=10>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>First Name<sup>*</sup></b>
<br>
<input type="text" name="firstName" value="" size=15 maxlength=20></td>
64
<td valign=top>
<b>Last Name<sup>*</sup></b>
<br>
<input type="text" name="lastName" value="" size=15 maxlength=20></td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>Password<sup>*</sup></b>
<br>
<input type="password" name="password1" size=10 value="" maxlength=10></td>
<td valign=top>
<b>Confirm Password<sup>*</sup></b>
<br>
<input type="password" name="password2" size=10 value="" maxlength=10></td>
<br>
</tr>
<tr bgcolor="#c8d8f8">
<b>E-Mail<sup>*</sup></b>
<br>
<input type="text" name="email" value="" size=25 maxlength=125>
<br>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>URL of your picture</b>
<br>
<input type="text" name="picture" size=50 maxlength=128>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
65
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
</head>
<body>
if([Link]("")*[Link]("")*[Link]("")*
[Link]("")*[Link]("")*[Link]("")==0||
[Link](passWord2)!=0){%>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>NickName<sup>*</sup></b>
<br>
<input type="text" name="nickName" size=10 value="<%=nickName %>" maxlength=10>
<%if([Link]("")==0){%>
<br/><font color="red">Ce champ est obligatoire</font>
<%}%>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>First Name<sup>*</sup></b>
<br>
<input type="text" name="firstName" value="<%=firstName %>" size=15 maxlength=20>
<%if([Link]("")==0){%>
<br/><font color="red">Ce champ est obligatoire</font>
66
<%}%>
</td>
<td valign=top>
<b>Last Name<sup>*</sup></b>
<br>
<input type="text" name="lastName" value="<%=lastName %>" size=15 maxlength=20>
<%if([Link]("")==0){%>
<br/><font color="red">Ce champ est obligatoire</font>
<%}%>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>Password<sup>*</sup></b>
<br>
<br/><input type="password" name="password1" size=10 value="" maxlength=10>
<%if([Link]("")==0){%>
<font color="red">Ce champ est obligatoire</font>
<%}%>
</td>
<td valign=top>
<b>Confirm Password<sup>*</sup></b>
<br>
<input type="password" name="password2" size=10 value="" maxlength=10>
<%if([Link](passWord1)!=0){%>
<br/><font color="red">Les mot de passe sont différents</font>
<%}%>
<%if([Link]("")==0){%>
<br/><font color="red">Ce champ est obligatoire</font>
<%}%>
</td>
<br>
</tr>
<tr bgcolor="#c8d8f8">
<b>E-Mail<sup>*</sup></b>
<br>
<input type="text" name="email" size=25 value="<%=email%>" maxlength=125>
<%if([Link]("")==0){%>
<br/><font color="red">Ce champ est obligatoire</font>
<%}%>
<br>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>URL of your picture</b>
<br>
<input type="text" name="picture" value="<%=url%>" size=50 maxlength=128>
67
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
</table>
</center>
<%}else{
if([Link](nickName, passWord1, firstName, lastName, email,
url)==false)
{%>
<META http-equiv="refresh" content="0;
URL=[Link]
<%}else{%>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form method=post action="[Link]">
<center>
<table cellpadding=4 cellspacing=2 border=0>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=1>
<b>NickName</b>
<br>
<input type="text" name="nickName" size=10 value="" maxlength=10>
</td>
<td valign=top>
68
<b>Password</b>
<br>
<input type="password" name="password" size=10 value="" maxlength=10></td>
<br>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<a href=[Link]>Register</a>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<a href="[Link]">Forgot your password<a>
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
[Link]
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title></title>
</head>
<body>
<form action="[Link]" method=post>
<center>
<table cellpadding=4 cellspacing=2 border=0>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>NickName<sup>*</sup></b>
<br>
<input type="text" name="nickName" size=10 value="" maxlength=10>
<font color="red">Erreur d'enregistrement. Veuillez Re-essayer avec un autre
pseudo</font>
69
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>First Name<sup>*</sup></b>
<br>
<input type="text" name="firstName" value="" size=15 maxlength=20></td>
<td valign=top>
<b>Last Name<sup>*</sup></b>
<br>
<input type="text" name="lastName" value="" size=15 maxlength=20></td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top>
<b>Password<sup>*</sup></b>
<br>
<input type="password" name="password1" size=10 value="" maxlength=10></td>
<td valign=top>
<b>Confirm Password<sup>*</sup></b>
<br>
<input type="password" name="password2" size=10 value="" maxlength=10></td>
<br>
</tr>
<tr bgcolor="#c8d8f8">
<b>E-Mail<sup>*</sup></b>
<br>
<input type="text" name="email" value="" size=25 maxlength=125>
<br>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=2>
<b>URL of your picture</b>
<br>
<input type="text" name="picture" size=50 maxlength=128>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Submit"> <input type="reset" value="Reset">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>
70
[Link]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"[Link]
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
</th>
<tr bgcolor="#c8d8f8">
<td valign=top colspan=1>
<b>NickName</b>
<br>
</td>
<td valign=top colspan=1>
<input type="text" name="nickName" size=10 value="" maxlength=10>
</td>
</tr>
<tr bgcolor="#c8d8f8">
<td align=center colspan=2>
<input type="submit" value="Recover your password">
</td>
</tr>
</table>
</form>
</body>
</html>
[Link]
<jsp:useBean id="IrcBean" scope="session" class="[Link]">
</jsp:useBean>
<jsp:setProperty name="IrcBean" property="*"/>
71
<body>
<%@page import="[Link].*" %>
<%@page import="[Link].*"%>
<%@page import="[Link].*"%>
<%@page import="[Link].*" %>
Properties props=[Link]();
[Link]("[Link]",host);
[Link]("[Link]","smtp");
<%
}
%>
</body>
</html>
72
4.2.3 Exemple d’exécution
[Link] Enregistrement
73
74
Remarques :
• Dans le cas où l’utilisateur ne remplie pas un champ obligatoire, un message d’erreur dans ce
champ est affiché pour rappeler l’utilisateur que ce dernier est obligatoire.
• Un message d’erreur apparaît sous le champ nickName indique à l’utilisateur de choisir un
autre nickName si ce dernier est déjà enregistré dans la base de données.
• Un message d’erreur apparaît sous le champ mot de passe si l’utilisateur a entré 2 mots de
passe différents.
75
[Link] Connexion
76
Remarques :
77
[Link] Récupération de mot passe (JAVAMAIL) :
Dans ce cas, on suppose que l’utilisateur a oublié son mot de passe. La procédure est d’indiquer
son nickName et de le récupérer dans sa boite email.
78
79
Remarques :
80
5 Conclusion
Après une pratique de base de la technologie JAVA en première année. Et une autre beaucoup plus
approfondie en deuxième année d’études. Nous sommes convaincus qu’ils restent beaucoup d’astuces
encore à connaître. C’est la raison pour laquelle nous avons choisie de faire le projet d’étude de
deuxième année exclusivement en JAVA.
Nous remercions M. DUCROT pour son cours de JAVA et ses conseils lors des TP.
81