JAVA


J2EE : MVC en pratique




|

Exrcice 1 
    
    L'objetcif de cet exercice est d'afficher la liste des vins avec un le nom du vin
    en critère.
    
    Schéma de classe : 
    
    	
    	
    	
    	Organisation des classes : 
    	
    	formation.mvc.resultat
    		- Vin
    		- Liste
    		- ListeVins
    	formation.mvc.bean
    		- TraitementVins
    	formation.mvc.servlet
    		- ServletVins
    	formation.mvc.util
    		- SQLUtil


 

|

Classe Vins, Liste et ListeVins : 
    
package formation.mvc.resultat;

/**
 * Représente un enregistrement de la table Vin.
 * Creation date: (24/11/2002 17:10:10)
 * @author: Administrator
 */
public class Vin {
	private java.lang.String codeVin;
	private java.lang.String code;
	private java.lang.String codePR;
	private java.lang.String nom;
	private java.lang.String cepage1;
	private java.lang.String cepage2;
	private java.lang.String cepage3;
	private java.lang.String cepage4;
	private java.lang.String etiquette;
	private java.lang.String codeClasse;
	private java.lang.String sousRegion;
	private java.lang.String codeAppellation;
	private java.lang.String codeType;
	private java.lang.String codeGarde;
/**
 * Vins constructeur.
 */
public Vin() {
	super();
}

public java.lang.String getCepage1() {
	return cepage1;
}

public java.lang.String getCepage2() {
	return cepage2;
}

public java.lang.String getCepage3() {
	return cepage3;
}

public java.lang.String getCepage4() {
	return cepage4;
}

public java.lang.String getCodeAppellation() {
	return codeAppellation;
}

public java.lang.String getCodeClasse() {
	return codeClasse;
}

public java.lang.String getCodeGarde() {
	return codeGarde;
}

public java.lang.String getCodePR() {
	return codePR;
}

public java.lang.String getCodeType() {
	return codeType;
}

public java.lang.String getCodeVin() {
	return codeVin;
}

public java.lang.String getEtiquette() {
	return etiquette;
}

public java.lang.String getNom() {
	return nom;
}

public java.lang.String getSousRegion() {
	return sousRegion;
}

public void setCepage1(java.lang.String newCepage1) {
	cepage1 = newCepage1;
}

public void setCepage2(java.lang.String newCepage2) {
	cepage2 = newCepage2;
}

public void setCepage3(java.lang.String newCepage3) {
	cepage3 = newCepage3;
}

public void setCepage4(java.lang.String newCepage4) {
	cepage4 = newCepage4;
}

public void setCodeAppellation(java.lang.String newCodeAppellation) {
	codeAppellation = newCodeAppellation;
}

public void setCodeClasse(java.lang.String newCodeClasse) {
	codeClasse = newCodeClasse;
}

public void setCodeGarde(java.lang.String newCodeGarde) {
	codeGarde = newCodeGarde;
}

public void setCodePR(java.lang.String newCodePR) {
	codePR = newCodePR;
}

public void setCodeType(java.lang.String newCodeType) {
	codeType = newCodeType;
}

public void setCodeVin(java.lang.String newCodeVin) {
	codeVin = newCodeVin;
}

public void setEtiquette(java.lang.String newEtiquette) {
	etiquette = newEtiquette;
}

public void setNom(java.lang.String newNom) {
	nom = newNom;
}

public void setSousRegion(java.lang.String newSousRegion) {
	sousRegion = newSousRegion;
}
}


package formation.mvc.resultat;

import java.util.*;

/**
 * Classe générique représentant une liste d'enregistrement.
 * Creation date: (24/11/2002 17:33:30)
 * @author: Administrator
 */
public class Liste {
	private int nbEnregLus;
	private java.util.Vector listeEnregistrement;
	private int nbiteration=20;
	private int nbEnregAff;
	private java.util.Hashtable listeCritere;

public Liste() {
	super();
}

public java.util.Hashtable getListeCritere() {
	return listeCritere;
}

public java.util.Vector getListeEnregistrement() {
	return listeEnregistrement;
}

public int getNbEnregAff() {
	return nbEnregAff;
}

public int getNbEnregLus() {
	return nbEnregLus;
}


public int getNbiteration() {
	return nbiteration;
}

public void setListeCritere(java.util.Hashtable newListeCritere) {
	listeCritere = newListeCritere;
}

public void setListeEnregistrement(java.util.Vector newListeEnregistrement) {
	listeEnregistrement = newListeEnregistrement;
}

public void setNbEnregAff(int newNbEnregAff) {
	nbEnregAff = newNbEnregAff;
}

public void setNbEnregLus(int newNbEnregLus) {
	nbEnregLus = newNbEnregLus;
}

public void setNbiteration(int newNbiteration) {
	nbiteration = newNbiteration;
}
}


package formation.mvc.resultat;

import java.util.Vector;
/**
 * Représente une liste de vins
 * Creation date: (24/11/2002 17:36:51)
 * @author: Administrator
 */
public class ListeVins extends Liste {
	private java.util.Hashtable criteres;

public ListeVins() {
	super();
}

public java.util.Hashtable getCriteres() {
	return criteres;
}

public void setCriteres(java.util.Hashtable newCriteres) {
	criteres = newCriteres;
}
}

|

Traitement des vins 
    

Super classe de la classe de TraitementVins. Cette classe gère la connexion à la BDD via le pool de connexions.

package formation.mvc.util;

import javax.sql.*;
import java.sql.Connection;
/**
 * Utilitaire SQL
 * Creation date: (24/11/2002 17:40:58)
 * @author: Administrator
 */
public class SQLUtil {
	private javax.sql.DataSource ds;

public SQLUtil() {
	super();
	initDataSource();
}

public Connection getPoolConnection() throws java.sql.SQLException {
	return ds.getConnection();
}

public Connection getPoolConnection(String user, String password)
	throws java.sql.SQLException {
	return ds.getConnection(user,password);
}

private void initDataSource() {
	try {
		
		java.util.Properties p = new java.util.Properties();
		
		p.put("javax.naming.Context.INITIAL_CONTEXT_FACTORY", 
			"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
			
		p.put("javax.naming.Context.PROVIDER_URL", "iiop:///");
		
		javax.naming.Context ctx = new javax.naming.InitialContext(p);

		ds = (DataSource)ctx.lookup("jdbc/BDVIN");
		
	} catch (Exception e) {
	}
}
}


package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;
/**
 * Classe permettant le traitement de la table vins
 * Creation date: (24/11/2002 17:09:56)
 * @author: Administrator
 */
public class TraitementVins extends SQLUtil{
/**
 * TraitementVins constructor comment.
 */
public TraitementVins() {
	super();
}
/**
 * Méthode appelée par la servlet qui retourne la liste des vins
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public ListeVins getDonnéesVins(Hashtable parametres) {
	ListeVins valRet = new ListeVins();
	try {
	  int nbIter = valRet.getNbiteration();
	  //Lecture selon bouton lire ou suivant ou precedent
	  if(parametres.get("suivant")!=null){
	    //Récupération du nombre d'enregistrement lus
		String nbEnregLus = (String)parametres.get("nbEnregLus");
		int nbEnreg = new Integer(nbEnregLus).intValue();
		valRet = lire(parametres,nbEnreg+nbIter,nbIter);
	  }else if(parametres.get("precedent")!=null){
	    //Récupération du nombre d'enregistrements lus
		String nbEnregLus = (String)parametres.get("nbEnregLus");
		//Récupération du nombre d'enregistrements affichés
		String nbEnregAffStr = (String)parametres.get("nbEnregAff");
		int nbEnreg = new Integer(nbEnregLus).intValue();
		int nbEnregAff = new Integer(nbEnregAffStr).intValue();
		//Positionnement du nombre à lire pour
		//le paramètre maxrows
		if(nbEnregAff!=nbIter){
			int tmp = nbIter-nbEnregAff ;
			nbEnreg = nbEnreg+tmp;
		}
		valRet = lire(parametres,nbEnreg-nbIter,nbIter);
	  }else{
		valRet = lire(parametres);
	  }
	  valRet.setCriteres(new Hashtable());
	  valRet.getCriteres().put("VIN_NOM","");
	  //Gestion des critères
	  String nom = (String)parametres.get("VIN_NOM");
	  if(nom!=null&&nom.trim().length()>0){
		valRet.getCriteres().put("VIN_NOM",nom);
	  }//end if
	} catch (Exception e) {
	  System.out.println(e.getMessage());
	} finally {
	  return valRet;	
	}
}
/**
 * Lecture de la table vins
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre) {
	return lire(parametre,0,20);
}
/**
 * Lecture de la table vins. Accès JDBC
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre, int nbEnreg, int nbIteration) {
	ListeVins valRet = new ListeVins();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_NOM like ?";
		//Récupération du paramètre VIN_NOM dans la Hashtable parametre
		String nom = ???????????????
		if(nom==null||nom.trim().length()==0){
			strSql = "Select * from vins";
		}//end if
		
		dbCon = getPoolConnection("BDVIN","BDVIN");
		//Créer la requête précompilé
		pstmt = ?????????????
		
		if(nbEnreg==0)nbEnreg = nbEnreg+nbIteration;
		//Limiter le nombre d'enregistrement à lire (Maxrows)
		
		
		if(nom!=null&&nom.trim().length()>0){
			//Alimenter le paramètre de la requête précompilé
			????????????????
		}//end if
		
		valRet.setListeEnregistrement(new Vector());
		rs = pstmt.executeQuery();

		int cpt = 0;
		int cptAff = 0;
		//Boucle tant qu'il y a des enregistrement à lire
		while (??????????????) {
			if(cpt>=(nbEnreg-nbIteration)){
				cptAff++;
				Vin vin = new Vin();
				//alimenter tous les attributs de la classe VINS
				//Avec les valeurs lues
				?????
				??????
				
				
				
				valRet.getListeEnregistrement().addElement(vin);
			}//end if
			cpt++;
		}//end while
		valRet.setNbEnregLus(cpt);
		valRet.setNbEnregAff(cptAff);
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
}
 
    
    Corrigé
package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;
/**
 * Classe permettant le traitement de la table vins
 * Creation date: (24/11/2002 17:09:56)
 * @author: Administrator
 */
public class TraitementVins extends SQLUtil{
/**
 * TraitementVins constructor comment.
 */
public TraitementVins() {
	super();
}
/**
 * Méthode appelée par la servlet qui retourne la liste des vins
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public ListeVins getDonnéesVins(Hashtable parametres) {
	ListeVins valRet = new ListeVins();
	try {
		int nbIter = valRet.getNbiteration();
		//Lecture selon bouton lire ou suivant ou precedent
		if(parametres.get("suivant")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			valRet = lire(parametres,nbEnreg+nbIter,nbIter);
		}else if(parametres.get("precedent")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			String nbEnregAffStr = (String)parametres.get("nbEnregAff");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			int nbEnregAff = new Integer(nbEnregAffStr).intValue();
			//Positionnement du nombre à lire pour
			//le paramètre maxrows
			if(nbEnregAff!=nbIter){
				int tmp = nbIter-nbEnregAff ;
				nbEnreg = nbEnreg+tmp;
			}
			valRet = lire(parametres,nbEnreg-nbIter,nbIter);
		}else{
			valRet = lire(parametres);
		}
		valRet.setCriteres(new Hashtable());
		valRet.getCriteres().put("VIN_NOM","");
		//Gestion des critères
		String nom = (String)parametres.get("VIN_NOM");
		if(nom!=null&&nom.trim().length()>0){
			valRet.getCriteres().put("VIN_NOM",nom);
		}//end if
	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		return valRet;	
	}
}
/**
 * Lecture de la table vins
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre) {
	return lire(parametre,0,20);
}
/**
 * Lecture de la table vins. Accès JDBC
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre, int nbEnreg, int nbIteration) {
	ListeVins valRet = new ListeVins();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_NOM like ?";
		String nom = (String)parametre.get("VIN_NOM");
		if(nom==null||nom.trim().length()==0){
			strSql = "Select * from vins";
		}//end if
		
		dbCon = getPoolConnection("BDVIN","BDVIN");
		pstmt = dbCon.prepareStatement(strSql);
		if(nbEnreg==0)nbEnreg = nbEnreg+nbIteration;
		pstmt.setMaxRows(nbEnreg);
		
		if(nom!=null&&nom.trim().length()>0){
			pstmt.setString(1,nom);
		}//end if
		valRet.setListeEnregistrement(new Vector());
		rs = pstmt.executeQuery();

		int cpt = 0;
		int cptAff = 0;
		while (rs.next()) {
			if(cpt>=(nbEnreg-nbIteration)){
				cptAff++;
				Vin vin = new Vin();
				vin.setCodeVin(rs.getString("VIN_CODE"));
				vin.setCodePR(rs.getString("PR_CODE"));
				vin.setNom(rs.getString("VIN_NOM"));
				vin.setCepage1(rs.getString("VIN_CEPAGE1"));
				vin.setCepage2(rs.getString("VIN_CEPAGE2"));
				vin.setCepage3(rs.getString("VIN_CEPAGE3"));
				vin.setCepage4(rs.getString("VIN_CEPAGE4"));
				vin.setEtiquette(rs.getString("VIN_ETIQUETTE"));
				vin.setCodeClasse(rs.getString("CLASS_CODE"));
				vin.setCodeGarde(rs.getString("GARDE_CODE"));
				vin.setCodeType(rs.getString("TYPE_CODE"));
				vin.setSousRegion(rs.getString("SREGION_CODE"));
				vin.setCodeAppellation(rs.getString("APPEL_CODE"));
				valRet.getListeEnregistrement().addElement(vin);
			}//end if
			cpt++;
		}//end while
		valRet.setNbEnregLus(cpt);
		valRet.setNbEnregAff(cptAff);
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
}
 

|

ServletVins 
    
package formation.mvc.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Servlet de gestion des vins.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletVins extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req,res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
  try {
	HttpSession session = req.getSession(true);
	//Récupération des paramétres de la requête HTTP
	//Alimentation d'une Hashtable avec les paramètres	
	Enumeration enum = ??????
	Hashtable params = new Hashtable();
	while (enum.hasMoreElements()) {
	  //pour chaque paramètre, récupérer la valeur
	  //Alimentation de la Hashtable params	
	}
	//Instanciation de l'Objet TraitementVins
	TraitementVins tVins = new TraitementVins();
	//Appel de la méthode qui retourne les données lues
	ListeVins lv = tVins.getDonnéesVins(params);
	//Mettre l'objet résultat dans un attribut de la requête
	req.?????????
	//Rediriger la requête ver le JSP /formation/vins.jsp
	getServletContext().?????????
  } catch (Exception e) {}
}


public ServletVins() {
	super();
}
}
 
    
    Corrigé
    
package formation.mvc.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Servlet de gestion des vins.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletVins extends HttpServlet {

public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req,res);
}

public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
  try {
	HttpSession session = req.getSession(true);
		
	Enumeration enum = req.getParameterNames();
	Hashtable params = new Hashtable();
	while (enum.hasMoreElements()) {
		String nom = (String)enum.nextElement();
		String valeur = (String)req.getParameter(nom);
		params.put(nom,valeur);
	}
	TraitementVins tVins = new TraitementVins();
	ListeVins lv = tVins.getDonnéesVins(params);
	req.setAttribute("VINS",lv);
	getServletContext().getRequestDispatcher("/formation/vins.jsp").forward(req,res);
  } catch (Exception e) {}
}


public ServletVins() {
	super();
}
}

|

JSP des vins 
    
<html>
<head>
<title>Gestion des vins</title>
</head>

<jsp:useBean class="formation.mvc.resultat.ListeVins" id="VINS" scope="request" />

<body>

<p>Liste des vins</p>
<form method="POST" action="/servlet/formation.mvc.servlet.ServletVins">
<input type="hidden" name="nbEnregLus" value="<%=VINS.getNbEnregLus()%>">
<input type="hidden" name="nbEnregAff" value="<%=VINS.getNbEnregAff()%>">
<%
String valeur = (String)VINS.getCriteres().get("VIN_NOM");
%>
<p>
Nom du vin : <input type="text" name="VIN_NOM" size="20" value="<%=valeur%>"><br>
<input type="submit" value="Lire" name="lire">
<input type="submit" value="Suivant" name="suivant">
<input type="submit" value="Précédent" name="precedent"> </p>
</form>
<table border="1">
<tr>
<th>Code</th>
<th>Nom</th>
<th>Cépage</th>
<th>Etiquette</th>
</tr>
<%
int vecLen = VINS.getListeEnregistrement().size();
for(int i=0;i<vecLen;i++){
formation.mvc.resultat.Vin vin = (formation.mvc.resultat.Vin)
VINS.getListeEnregistrement().elementAt(i);

%>
<tr>
<td><%=vin.getCodeVin()%>&nbsp;</td>
<td><%=vin.getNom()%>&nbsp;</td>
<td><%=vin.getCepage1()%>&nbsp;</td>
<td><%=vin.getEtiquette()%>&nbsp;</td>
</tr>
<%}//end for%>


</table>

</body>
</html>

 

|

Traitement des vins 
    

Ajout de la maintenance de la table vin dans notre exercice :

package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;
/**
 * Classe peremttant le traitement de la table vins
 * Creation date: (24/11/2002 17:09:56)
 * @author: Administrator
 */
public class TraitementVins extends SQLUtil{
/**
 * TraitementVins constructor comment.
 */
public TraitementVins() {
	super();
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin delete(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "delete from VINS where VIN_CODE=? ";

		int ret = 0;
		try {
			
			//Coder la suppression dans la basse de données 
			//Utiliser les méthodes setXXX de l'objet PreparedStatement
			
			//Exécuter l'ordre SQL
			ret = ????;

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Suppression effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Suppression invalidée");
			}//end if
			
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public ListeVins getDonnéesVins(Hashtable parametres) {
	ListeVins valRet = new ListeVins();
	try {
		int nbIter = valRet.getNbiteration();
		//Lecture selon bouton lire ou suivant ou precedent
		if(parametres.get("suivant")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			valRet = lire(parametres,nbEnreg+nbIter,nbIter);
		}else if(parametres.get("precedent")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			String nbEnregAffStr = (String)parametres.get("nbEnregAff");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			int nbEnregAff = new Integer(nbEnregAffStr).intValue();
			//Positionnement du nombre à lire pour
			//le paramètre maxrows
			if(nbEnregAff!=nbIter){
				int tmp = nbIter-nbEnregAff ;
				nbEnreg = nbEnreg+tmp;
			}
			valRet = lire(parametres,nbEnreg-nbIter,nbIter);
		}else{
			valRet = lire(parametres);
		}
		valRet.setCriteres(new Hashtable());
		valRet.getCriteres().put("VIN_NOM","");
		//Gestion des critères
		String nom = (String)parametres.get("VIN_NOM");
		if(nom!=null&&nom.trim().length()>0){
			valRet.getCriteres().put("VIN_NOM",nom);
		}//end if
	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		return valRet;	
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public Vin getFicheVins(Hashtable parametres) {
	Vin valRet =  null;
	try {

		if(parametres.get("update")!=null){
			valRet = update(parametres);
		}else if(parametres.get("delete")!=null){
			valRet = delete(parametres);
		}else if(parametres.get("insert")!=null){
			valRet = insert(parametres);
		}else{
			valRet = lireFiche(parametres);
		}//end if
		
	} catch (Exception e) {
	} finally {
		return valRet;	
	}
}
/**
 * Méthode qui récupère les paramètres saisis par l'utilisateur
 * Creation date: (12/12/2002 21:24:50)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin getParametreVin(Hashtable param) {
	Vin valRet = new Vin();
	try {
		valRet.setCodeVin((String)param.get("VIN_CODE"));
		valRet.setCodePR((String)param.get("PR_CODE"));
		valRet.setNom((String)param.get("VIN_NOM"));
		valRet.setCepage1((String)param.get("VIN_CEPAGE1"));
		valRet.setCepage2((String)param.get("VIN_CEPAGE2"));
		valRet.setCepage3((String)param.get("VIN_CEPAGE3"));
		valRet.setCepage4((String)param.get("VIN_CEPAGE4"));
		valRet.setEtiquette((String)param.get("VIN_ETIQUETTE"));
		valRet.setCodeClasse((String)param.get("CLASS_CODE"));
		valRet.setCodeGarde((String)param.get("GARDE_CODE"));
		valRet.setCodeType((String)param.get("TYPE_CODE"));
		valRet.setSousRegion((String)param.get("SREGION_CODE"));
		valRet.setCodeAppellation((String)param.get("APPEL_CODE"));		
	} finally {
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin insert(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);

		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "insert into VINS (VIN_NOM, PR_CODE, ";
		strSql+=" VIN_CEPAGE1, VIN_CEPAGE2, VIN_CEPAGE3, VIN_CEPAGE4, ";
		strSql+=" VIN_ETIQUETTE, CLASS_CODE, GARDE_CODE, TYPE_CODE, ";
		strSql+=" SREGION_CODE, APPEL_CODE, VIN_CODE)";
		strSql+=" values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

		int ret = 0;
		try {
			//Coder l'insertion dans la basse de données 
			//Utiliser les méthodes setXXX de l'objet PreparedStatement
			
			//Exécuter l'ordre SQL
			ret = ????;

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Création effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Création invalidée");
			}
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre) {
	return lire(parametre,0,20);
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre, int nbEnreg, int nbIteration) {
	ListeVins valRet = new ListeVins();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_NOM like ?";
		String nom = (String)parametre.get("VIN_NOM");
		if(nom==null||nom.trim().length()==0){
			strSql = "Select * from vins";
		}//end if
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		pstmt = dbCon.prepareStatement(strSql);
		if(nbEnreg==0)nbEnreg = nbEnreg+nbIteration;
		pstmt.setMaxRows(nbEnreg);
		
		if(nom!=null&&nom.trim().length()>0){
			pstmt.setString(1,nom);
		}//end if
		valRet.setListeEnregistrement(new Vector());
		rs = pstmt.executeQuery();

		int cpt = 0;
		int cptAff = 0;
		while (rs.next()) {
			if(cpt>=(nbEnreg-nbIteration)){
				cptAff++;
				Vin vin = new Vin();
				vin.setCodeVin(rs.getString("VIN_CODE"));
				vin.setCodePR(rs.getString("PR_CODE"));
				vin.setNom(rs.getString("VIN_NOM"));
				vin.setCepage1(rs.getString("VIN_CEPAGE1"));
				vin.setCepage2(rs.getString("VIN_CEPAGE2"));
				vin.setCepage3(rs.getString("VIN_CEPAGE3"));
				vin.setCepage4(rs.getString("VIN_CEPAGE4"));
				vin.setEtiquette(rs.getString("VIN_ETIQUETTE"));
				vin.setCodeClasse(rs.getString("CLASS_CODE"));
				vin.setCodeGarde(rs.getString("GARDE_CODE"));
				vin.setCodeType(rs.getString("TYPE_CODE"));
				vin.setSousRegion(rs.getString("SREGION_CODE"));
				vin.setCodeAppellation(rs.getString("APPEL_CODE"));
				valRet.getListeEnregistrement().addElement(vin);
			}//end if
			cpt++;
		}//end while
		valRet.setNbEnregLus(cpt);
		valRet.setNbEnregAff(cptAff);
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public Vin lireFiche(Hashtable parametre) {
	Vin valRet = new Vin();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_CODE = ?";
		String codeVin = (String)parametre.get("VIN_CODE");
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		//Coder la lecture d'un enregistrement de la table VIN
		// lire l'enregistrement, et le stocker dans l'objet résultat
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin update(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "Update VINS set VIN_NOM=?, PR_CODE=?, ";
		strSql+=" VIN_CEPAGE1=?, VIN_CEPAGE2=?, VIN_CEPAGE3=?, VIN_CEPAGE4=?, ";
		strSql+=" VIN_ETIQUETTE=?, CLASS_CODE=?, GARDE_CODE=?, TYPE_CODE=?, ";
		strSql+=" SREGION_CODE=?, APPEL_CODE=? Where VIN_CODE=?";

		int ret = 0;
		try {
			
			//Coder la mise à jour dans la basse de données 
			//Utiliser les méthodes setXXX de l'objet PreparedStatement
			
			//Exécuter l'ordre SQL
			ret = ????;

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Modification effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Modification invalidée");
			}
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
}
 
    
    Corrigé
package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;
/**
 * Classe peremttant le traitement de la table vins
 * Creation date: (24/11/2002 17:09:56)
 * @author: Administrator
 */
public class TraitementVins extends SQLUtil{
/**
 * TraitementVins constructor comment.
 */
public TraitementVins() {
	super();
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin delete(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "delete from VINS where VIN_CODE=? ";

		int ret = 0;
		try {
			
			pstmt = dbCon.prepareStatement(strSql);
			pstmt.setString(1, valRet.getCodeVin());

			ret = pstmt.executeUpdate();

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Suppression effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Suppression invalidée");
			}//end if
			
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public ListeVins getDonnéesVins(Hashtable parametres) {
	ListeVins valRet = new ListeVins();
	try {
		int nbIter = valRet.getNbiteration();
		//Lecture selon bouton lire ou suivant ou precedent
		if(parametres.get("suivant")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			valRet = lire(parametres,nbEnreg+nbIter,nbIter);
		}else if(parametres.get("precedent")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			String nbEnregAffStr = (String)parametres.get("nbEnregAff");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			int nbEnregAff = new Integer(nbEnregAffStr).intValue();
			//Positionnement du nombre à lire pour
			//le paramètre maxrows
			if(nbEnregAff!=nbIter){
				int tmp = nbIter-nbEnregAff ;
				nbEnreg = nbEnreg+tmp;
			}
			valRet = lire(parametres,nbEnreg-nbIter,nbIter);
		}else{
			valRet = lire(parametres);
		}
		valRet.setCriteres(new Hashtable());
		valRet.getCriteres().put("VIN_NOM","");
		//Gestion des critères
		String nom = (String)parametres.get("VIN_NOM");
		if(nom!=null&&nom.trim().length()>0){
			valRet.getCriteres().put("VIN_NOM",nom);
		}//end if
	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		return valRet;	
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public Vin getFicheVins(Hashtable parametres) {
	Vin valRet =  null;
	try {

		if(parametres.get("update")!=null){
			valRet = update(parametres);
		}else if(parametres.get("delete")!=null){
			valRet = delete(parametres);
		}else if(parametres.get("insert")!=null){
			valRet = insert(parametres);
		}else{
			valRet = lireFiche(parametres);
		}//end if
		
	} catch (Exception e) {
	} finally {
		return valRet;	
	}
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:24:50)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin getParametreVin(Hashtable param) {
	Vin valRet = new Vin();
	try {
		valRet.setCodeVin((String)param.get("VIN_CODE"));
		valRet.setCodePR((String)param.get("PR_CODE"));
		valRet.setNom((String)param.get("VIN_NOM"));
		valRet.setCepage1((String)param.get("VIN_CEPAGE1"));
		valRet.setCepage2((String)param.get("VIN_CEPAGE2"));
		valRet.setCepage3((String)param.get("VIN_CEPAGE3"));
		valRet.setCepage4((String)param.get("VIN_CEPAGE4"));
		valRet.setEtiquette((String)param.get("VIN_ETIQUETTE"));
		valRet.setCodeClasse((String)param.get("CLASS_CODE"));
		valRet.setCodeGarde((String)param.get("GARDE_CODE"));
		valRet.setCodeType((String)param.get("TYPE_CODE"));
		valRet.setSousRegion((String)param.get("SREGION_CODE"));
		valRet.setCodeAppellation((String)param.get("APPEL_CODE"));		
	} finally {
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin insert(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);

		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "insert into VINS (VIN_NOM, PR_CODE, ";
		strSql+=" VIN_CEPAGE1, VIN_CEPAGE2, VIN_CEPAGE3, VIN_CEPAGE4, ";
		strSql+=" VIN_ETIQUETTE, CLASS_CODE, GARDE_CODE, TYPE_CODE, ";
		strSql+=" SREGION_CODE, APPEL_CODE, VIN_CODE)";
		strSql+=" values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

		int ret = 0;
		try {
			
			pstmt = dbCon.prepareStatement(strSql);
			pstmt.setString(1, valRet.getNom());
			pstmt.setString(2, valRet.getCodePR());
			pstmt.setString(3, valRet.getCepage1());
			pstmt.setString(4, valRet.getCepage2());
			pstmt.setString(5, valRet.getCepage3());
			pstmt.setString(6, valRet.getCepage4());
			pstmt.setString(7, valRet.getEtiquette());
			pstmt.setString(8, valRet.getCodeClasse());
			pstmt.setString(9, valRet.getCodeGarde());
			pstmt.setString(10, valRet.getCodeType());
			pstmt.setString(11, valRet.getSousRegion());
			pstmt.setString(12, valRet.getCodeAppellation());
			pstmt.setString(13, valRet.getCodeVin());

			ret = pstmt.executeUpdate();

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Création effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Création invalidée");
			}
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre) {
	return lire(parametre,0,20);
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre, int nbEnreg, int nbIteration) {
	ListeVins valRet = new ListeVins();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_NOM like ?";
		String nom = (String)parametre.get("VIN_NOM");
		if(nom==null||nom.trim().length()==0){
			strSql = "Select * from vins";
		}//end if
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		pstmt = dbCon.prepareStatement(strSql);
		if(nbEnreg==0)nbEnreg = nbEnreg+nbIteration;
		pstmt.setMaxRows(nbEnreg);
		
		if(nom!=null&&nom.trim().length()>0){
			pstmt.setString(1,nom);
		}//end if
		valRet.setListeEnregistrement(new Vector());
		rs = pstmt.executeQuery();

		int cpt = 0;
		int cptAff = 0;
		while (rs.next()) {
			if(cpt>=(nbEnreg-nbIteration)){
				cptAff++;
				Vin vin = new Vin();
				vin.setCodeVin(rs.getString("VIN_CODE"));
				vin.setCodePR(rs.getString("PR_CODE"));
				vin.setNom(rs.getString("VIN_NOM"));
				vin.setCepage1(rs.getString("VIN_CEPAGE1"));
				vin.setCepage2(rs.getString("VIN_CEPAGE2"));
				vin.setCepage3(rs.getString("VIN_CEPAGE3"));
				vin.setCepage4(rs.getString("VIN_CEPAGE4"));
				vin.setEtiquette(rs.getString("VIN_ETIQUETTE"));
				vin.setCodeClasse(rs.getString("CLASS_CODE"));
				vin.setCodeGarde(rs.getString("GARDE_CODE"));
				vin.setCodeType(rs.getString("TYPE_CODE"));
				vin.setSousRegion(rs.getString("SREGION_CODE"));
				vin.setCodeAppellation(rs.getString("APPEL_CODE"));
				valRet.getListeEnregistrement().addElement(vin);
			}//end if
			cpt++;
		}//end while
		valRet.setNbEnregLus(cpt);
		valRet.setNbEnregAff(cptAff);
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public Vin lireFiche(Hashtable parametre) {
	Vin valRet = new Vin();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = "Select * from vins where VIN_CODE = ?";
		String codeVin = (String)parametre.get("VIN_CODE");
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		pstmt = dbCon.prepareStatement(strSql);
		
		pstmt.setString(1,codeVin);

		rs = pstmt.executeQuery();

		if (rs.next()) {
			valRet.setCodeVin(rs.getString("VIN_CODE"));
			valRet.setCodePR(rs.getString("PR_CODE"));
			valRet.setNom(rs.getString("VIN_NOM"));
			valRet.setCepage1(rs.getString("VIN_CEPAGE1"));
			valRet.setCepage2(rs.getString("VIN_CEPAGE2"));
			valRet.setCepage3(rs.getString("VIN_CEPAGE3"));
			valRet.setCepage4(rs.getString("VIN_CEPAGE4"));
			valRet.setEtiquette(rs.getString("VIN_ETIQUETTE"));
			valRet.setCodeClasse(rs.getString("CLASS_CODE"));
			valRet.setCodeGarde(rs.getString("GARDE_CODE"));
			valRet.setCodeType(rs.getString("TYPE_CODE"));
			valRet.setSousRegion(rs.getString("SREGION_CODE"));
			valRet.setCodeAppellation(rs.getString("APPEL_CODE"));
		}//end if
	} finally {
		try {
			if(rs!=null)rs.close();
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {
		}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (12/12/2002 21:27:22)
 * @return formation.mvc.resultat.Vin
 * @param param java.util.Hashtable
 */
public Vin update(Hashtable param) {
	Vin valRet = null;
	PreparedStatement pstmt = null;
	Connection dbCon = null;
	try {
		valRet = getParametreVin(param);
		
		dbCon = getPoolConnection("FORMATION1","FUN");
		dbCon.setAutoCommit(false);
		
		String strSql = "Update VINS set VIN_NOM=?, PR_CODE=?, ";
		strSql+=" VIN_CEPAGE1=?, VIN_CEPAGE2=?, VIN_CEPAGE3=?, VIN_CEPAGE4=?, ";
		strSql+=" VIN_ETIQUETTE=?, CLASS_CODE=?, GARDE_CODE=?, TYPE_CODE=?, ";
		strSql+=" SREGION_CODE=?, APPEL_CODE=? Where VIN_CODE=?";

		int ret = 0;
		try {
			
			pstmt = dbCon.prepareStatement(strSql);
			pstmt.setString(1, valRet.getNom());
			pstmt.setString(2, valRet.getCodePR());
			pstmt.setString(3, valRet.getCepage1());
			pstmt.setString(4, valRet.getCepage2());
			pstmt.setString(5, valRet.getCepage3());
			pstmt.setString(6, valRet.getCepage4());
			pstmt.setString(7, valRet.getEtiquette());
			pstmt.setString(8, valRet.getCodeClasse());
			pstmt.setString(9, valRet.getCodeGarde());
			pstmt.setString(10, valRet.getCodeType());
			pstmt.setString(11, valRet.getSousRegion());
			pstmt.setString(12, valRet.getCodeAppellation());
			pstmt.setString(13, valRet.getCodeVin());

			ret = pstmt.executeUpdate();

			if(ret>0){
				dbCon.commit();
				valRet.setErreur("Modification effectuée");
			}else{
				dbCon.rollback();
				valRet.setErreur("Modification invalidée");
			}
		} catch (SQLException se) {
			dbCon.rollback();
			valRet.setErreur(se.getMessage());
		}

	} finally {
		try {
			if(pstmt!=null)pstmt.close();
			if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
}
 

|

ServletVins Version 2
    
package formation.mvc.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Insert the type's description here.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletVins extends HttpServlet {

/**
 * doGet method comment.
 */
public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req,res);
}
/**
 * doPost method comment.
 */
public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	try {
		HttpSession session = req.getSession(true);
		//Récupération des paramètres
		Enumeration enum = req.getParameterNames();
		Hashtable params = new Hashtable();
		while (enum.hasMoreElements()) {
			String nom = (String)enum.nextElement();
			String valeur = (String)req.getParameter(nom);
			params.put(nom,valeur);
		}
		
		String nomJsp = "/formation/vins.jsp";
		//Instanciation du traitement des vins (JavaBean)
		//Test du paramètre caché nous permettant de
		//savoir si l'on traite la fichie ou la liste
		//Si on traite la fiche appel de la méthode
		//getFicheVins et mettre le bon nom du JSP dans la
		//variable nomJSP
		//sinon appel de la méhtode getDonnéesVins
		//Positionner l'objet résultat dans la requête HTTP
		
		//Redirection de la réponse vers le JSP
		getServletContext().getRequestDispatcher(nomJsp).forward(req,res);
	} catch (Exception e) {
	}
}

/**
 * ServletVins constructor comment.
 */
public ServletVins() {
	super();
}
}
 
    
    Corrigé
    
package formation.mvc.servlet;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Insert the type's description here.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletVins extends HttpServlet {

/**
 * doGet method comment.
 */
public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req,res);
}
/**
 * doPost method comment.
 */
public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	try {
		HttpSession session = req.getSession(true);
		//Récupération des paramètres
		Enumeration enum = req.getParameterNames();
		Hashtable params = new Hashtable();
		while (enum.hasMoreElements()) {
			String nom = (String)enum.nextElement();
			String valeur = (String)req.getParameter(nom);
			params.put(nom,valeur);
		}
		
		String nomJsp = "/formation/vins.jsp";
		//Instanciation du traitement des vins (JavaBean)
		TraitementVins tVins = new TraitementVins();
		if(params.get("fiche")!=null){
			nomJsp = "/formation/fichevin.jsp";
			Vin v = tVins.getFicheVins(params);
			req.setAttribute("VINS",v);
		}else{
			ListeVins lv = tVins.getDonnéesVins(params);
			req.setAttribute("VINS",lv);
		}//end if
		//Redirection de la réponse vers le JSP
		getServletContext().getRequestDispatcher(nomJsp).forward(req,res);
	} catch (Exception e) {
	}
}

/**
 * ServletVins constructor comment.
 */
public ServletVins() {
	super();
}
}

|

JSP fiche vin
    
<jsp:useBean class="formation.mvc.resultat.Vin" id="VINS" scope="request" />

<html>

<head>

<title>Gestion des vins</title>

</head>

<body>

<form method="POST" action="/servlet/formation.mvc.servlet.ServletVins">

<input type="hidden" name="fiche" value="true">

<font color="rgb(255,0,0)"><%=VINS.getErreur()%></font><br>

<table border="0" width="70%">

<tr>

<td width="25%">Code vin</td>

<td width="25%"><input type="text" name="VIN_CODE" size="20" value="<%=VINS.getCodeVin()%>"></td>

<td width="25%">Nom du vin</td>

<td width="25%"><input type="text" name="VIN_NOM" size="20" value="<%=VINS.getNom()%>"></td>

</tr>

<tr>

<td width="25%">Producteur</td>

<td width="25%"><input type="text" name="PR_CODE" size="20" value="<%=VINS.getCodePR()%>"></td>

<td width="25%">Cépage 1</td>

<td width="25%"><input type="text" name="VIN_CEPAGE1" size="20" value="<%=VINS.getCepage1()%>"></td>

</tr>

<tr>

<td width="25%">Cépage 2</td>

<td width="25%"><input type="text" name="VIN_CEPAGE2" size="20" value="<%=VINS.getCepage2()%>"></td>

<td width="25%">Cépage 3</td>

<td width="25%"><input type="text" name="VIN_CEPAGE3" size="20" value="<%=VINS.getCepage3()%>"></td>

</tr>

<tr>

<td width="25%">Cépage 4</td>

<td width="25%"><input type="text" name="VIN_CEPAGE4" size="20" value="<%=VINS.getCepage4()%>"></td>

<td width="25%">Etiquette</td>

<td width="25%"><input type="text" name="VIN_ETIQUETTE" size="20" value="<%=VINS.getEtiquette()%>"></td>

</tr>

<tr>

<td width="25%">Classe</td>

<td width="25%"><input type="text" name="CLASS_CODE" size="20" value="<%=VINS.getCodeClasse()%>"></td>

<td width="25%">Garde</td>

<td width="25%"><input type="text" name="GARDE_CODE" size="20" value="<%=VINS.getCodeGarde()%>"></td>

</tr>

<tr>

<td width="25%">Type</td>

<td width="25%"><input type="text" name="TYPE_CODE" size="20" value="<%=VINS.getCodeType()%>"></td>

<td width="25%">Région</td>

<td width="25%"><input type="text" name="SREGION_CODE" size="20" value="<%=VINS.getSousRegion()%>"></td>

</tr>

<tr>

<td width="25%">Appellation</td>

<td width="25%"><input type="text" name="APPEL_CODE" size="20" value="<%=VINS.getCodeAppellation()%>"></td>

<td width="25%">&nbsp;</td>

<td width="25%">&nbsp;</td>

</tr>

</table>

<p><input type="submit" value="Modifier" name="update"><input type="submit" value="Créer" name="insert"><input type="submit" value="Supprimer" name="delete"></p>

</form>

</body>

</html>


        

 

|

Exercice 2 
    
    L'objectif de cet exercice est d'afficher la liste des enregistrements d'une table.
    
    Schéma de classe : 
    
    	
    	
    	
    	Organisation des classes : 
    	
    	formation.mvc.resultat
    		- Liste
    	formation.mvc.bean
    		- TraitementListe
    	formation.mvc.servlet
    		- ServletListe
    	formation.mvc.util
    		- SQLUtil


 

|

Classe Liste : 
    
package formation.mvc.resultat;

import java.util.*;

/**
 * Classe générique représentant une liste d'enregistrement.
 * Creation date: (24/11/2002 17:33:30)
 * @author: Administrator
 */
public class Liste {
	private int nbEnregLus;
	private java.util.Vector listeEnregistrement;
	private int nbiteration=20;
	private int nbEnregAff;
	private java.util.Hashtable listeCritere;

public Liste() {
	super();
}

public java.util.Hashtable getListeCritere() {
	return listeCritere;
}

public java.util.Vector getListeEnregistrement() {
	return listeEnregistrement;
}

public int getNbEnregAff() {
	return nbEnregAff;
}

public int getNbEnregLus() {
	return nbEnregLus;
}


public int getNbiteration() {
	return nbiteration;
}

public void setListeCritere(java.util.Hashtable newListeCritere) {
	listeCritere = newListeCritere;
}

public void setListeEnregistrement(java.util.Vector newListeEnregistrement) {
	listeEnregistrement = newListeEnregistrement;
}

public void setNbEnregAff(int newNbEnregAff) {
	nbEnregAff = newNbEnregAff;
}

public void setNbEnregLus(int newNbEnregLus) {
	nbEnregLus = newNbEnregLus;
}

public void setNbiteration(int newNbiteration) {
	nbiteration = newNbiteration;
}
}


|

Traitement des Listes
    

Super classe de la classe de TraitementListes. Cette classe gère la connexion à la BDD via le pool de connexions.

package formation.mvc.util;

import javax.sql.*;
import java.sql.Connection;
/**
 * Utilitaire SQL
 * Creation date: (24/11/2002 17:40:58)
 * @author: Administrator
 */
public class SQLUtil {
	private javax.sql.DataSource ds;

public SQLUtil() {
	super();
	initDataSource();
}

public Connection getPoolConnection() throws java.sql.SQLException {
	return ds.getConnection();
}

public Connection getPoolConnection(String user, String password)
	throws java.sql.SQLException {
	return ds.getConnection(user,password);
}

private void initDataSource() {
	try {
		
		java.util.Properties p = new java.util.Properties();
		
		p.put("javax.naming.Context.INITIAL_CONTEXT_FACTORY", 
			"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
			
		p.put("javax.naming.Context.PROVIDER_URL", "iiop:///");
		
		javax.naming.Context ctx = new javax.naming.InitialContext(p);

		ds = (DataSource)ctx.lookup("jdbc/BDVIN");
		
	} catch (Exception e) {
	}
}
}


package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;

/**
 * Insert the type's description here.
 * Creation date: (25/11/2002 13:25:03)
 * @author: Administrator
 */
public class TraitementListe extends SQLUtil{
	private java.lang.String requetSql;
	private java.util.Vector criteres;
/**
 * TraitementListe constructor comment.
 */
public TraitementListe() {
	super();
}
/**
 * Insert the method's description here.
 * Creation date: (25/11/2002 13:30:33)
 * @return java.util.Vector
 */
public java.util.Vector getCriteres() {
	return criteres;
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public Liste getDonnees(Hashtable parametres, String requeteSql, Vector clauseWhere) {
	Liste valRet = new Liste();
	try {
		
		setRequetSql(requeteSql);
		setCriteres(clauseWhere);
		
		int nbIter = valRet.getNbiteration();
		//Lecture selon bouton lire ou suivant ou precedent
		if(parametres.get("suivant")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			valRet = lire(parametres,nbEnreg+nbIter,nbIter);
		}else if(parametres.get("precedent")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			String nbEnregAffStr = (String)parametres.get("nbEnregAff");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			int nbEnregAff = new Integer(nbEnregAffStr).intValue();
			//Positionnement du nombre à lire pour
			//le paramètre maxrows
			if(nbEnregAff!=nbIter){
				int tmp = nbIter-nbEnregAff ;
				nbEnreg = nbEnreg+tmp;
			}
			valRet = lire(parametres,nbEnreg-nbIter,nbIter);
		}else{
			valRet = lire(parametres);
		}
	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		return valRet;	
	}
}
/**
 * Insert the method's description here.
 * Creation date: (25/11/2002 13:30:10)
 * @return java.lang.String
 */
public java.lang.String getRequetSql() {
	return requetSql;
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre) {
	return lire(parametre,0,20);
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:44:11)
 * @return formation.mvc.resultat.ListeVins
 */
public ListeVins lire(Hashtable parametre, int nbEnreg, int nbIteration) {
	ListeVins valRet = new ListeVins();
	Connection dbCon = null;
	PreparedStatement pstmt = null;
	ResultSet rs = null;
	try {
		//Formatage de la requête SQL
		String strSql = getRequetSql();
		String nomParam = (String)getCriteres().elementAt(0);
		String nom = (String)parametre.get(nomParam);
		valRet.setListeCritere(new Hashtable());		
		if(nom==null||nom.trim().length()==0){
			strSql = strSql.substring(0,strSql.toLowerCase().indexOf("where"));
			valRet.getListeCritere().put(nomParam,"");
		}else{
			valRet.getListeCritere().put(nomParam,nom);
		}//end if
		
		dbCon = getPoolConnection("BDVIN","BDVIN");
		pstmt = dbCon.prepareStatement(strSql);
		if(nbEnreg==0)nbEnreg = nbEnreg+nbIteration;
		pstmt.setMaxRows(nbEnreg);
		
		if(nom!=null&&nom.trim().length()>0){
			pstmt.setString(1,nom);
		}//end if
		valRet.setListeEnregistrement(new Vector());
		rs = pstmt.executeQuery();
		int nbCol = rs.getMetaData().getColumnCount();
		int cpt = 0;
		int cptAff = 0;
		
		while (rs.next()) {
			if(cpt>=(nbEnreg-nbIteration)){
			  Hashtable enreg = new Hashtable();
			  cptAff++;
			  for (int i = 1; i <= nbCol; i++){
				String val = rs.getString(i);
				if(val==null)val="";
				enreg.put(rs.getMetaData().getColumnName(i).trim(),val);
			  }
			  valRet.getListeEnregistrement().addElement(enreg);
			}//end if
			cpt++;
		}//end while
		valRet.setNbEnregLus(cpt);
		valRet.setNbEnregAff(cptAff);
	} finally {
		try {
		  if(rs!=null)rs.close();
		  if(pstmt!=null)pstmt.close();
		  if(dbCon!=null)dbCon.close();
		} catch (SQLException e) {}
		return valRet;
	}
}
/**
 * Insert the method's description here.
 * Creation date: (25/11/2002 13:30:33)
 * @param newCriteres java.util.Vector
 */
public void setCriteres(java.util.Vector newCriteres) {
	criteres = newCriteres;
}
/**
 * Insert the method's description here.
 * Creation date: (25/11/2002 13:30:10)
 * @param newRequetSql java.lang.String
 */
public void setRequetSql(java.lang.String newRequetSql) {
	requetSql = newRequetSql;
}
}
 
    
    Corrigé
package formation.mvc.bean;

import javax.sql.DataSource;
import java.sql.*;
import java.util.*;
import formation.mvc.resultat.*;
import formation.mvc.util.*;

/**
 * Insert the type's description here.
 * Creation date: (25/11/2002 13:25:03)
 * @author: Administrator
 */
public class TraitementListe extends SQLUtil{
	private java.lang.String requetSql;
	private java.util.Vector criteres;
/**
 * TraitementListe constructor comment.
 */
public TraitementListe() {
	super();
}
/**
 * Insert the method's description here.
 * Creation date: (25/11/2002 13:30:33)
 * @return java.util.Vector
 */
public java.util.Vector getCriteres() {
	return criteres;
}
/**
 * Insert the method's description here.
 * Creation date: (24/11/2002 17:39:04)
 * @return formation.mvc.resultat.ListeVins
 * @param parametres java.util.Hashtable
 */
public Liste getDonnees(Hashtable parametres, String requeteSql, Vector clauseWhere) {
	Liste valRet = new Liste();
	try {
		
		setRequetSql(requeteSql);
		setCriteres(clauseWhere);
		
		int nbIter = valRet.getNbiteration();
		//Lecture selon bouton lire ou suivant ou precedent
		if(parametres.get("suivant")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			valRet = lire(parametres,nbEnreg+nbIter,nbIter);
		}else if(parametres.get("precedent")!=null){
			String nbEnregLus = (String)parametres.get("nbEnregLus");
			String nbEnregAffStr = (String)parametres.get("nbEnregAff");
			int nbEnreg = new Integer(nbEnregLus).intValue();
			int nbEnregAff = new Integer(nbEnregAffStr).intValue();
			//Positionnement du nombre à lire pour
			//le paramètre maxrows
			if(nbEnregAff!=nbIter){
				int tmp = nbIter-nbEnregAff ;
				nbEnreg = nbEnreg+tmp;
			}
			valRet = lire(parametres,nbEnreg-nbIter,nbIter);
		}else{
			valRet = lire(parametres);
		}
	} catch (Exception e) {
		System.out.println(e.getMessage());
	} finally {
		return valRet;	
	}
}

public java.lang.String getRequetSql() {
	return requetSql;
}

public void setCriteres(java.util.Vector newCriteres) {
	criteres = newCriteres;
}

public void setRequetSql(java.lang.String newRequetSql) {
	requetSql = newRequetSql;
}
}
 

|

ServletListe 
    
package formation.mvc.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Insert the type's description here.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletListe extends HttpServlet {

/**
 * doGet method comment.
 */
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
	doPost(req,res);
}
/**
 * doPost method comment.
 */
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
	try {
		HttpSession session = req.getSession(true);
		//Lecture des paramètres
		Enumeration enum = ?????????
		Hashtable params = new Hashtable();
		while (enum.hasMoreElements()) {
	  		//pour chaque paramètre, récupérer la valeur
	  		//Alimentation de la Hashtable params	
		}
		String strSql = null;
		Vector vec = new Vector();
		//Récupération de l'écran à traiter
		String ecran = ?????????
		if(ecran.trim().equalsIgnoreCase("vins")){
			strSql = "Select * from vins where VIN_NOM like ?";
			vec.addElement("VIN_NOM");
		}else if(ecran.trim().equalsIgnoreCase("hotelresto")){
			strSql = "Select * from hotelresto where HR_NOM like ?";
			vec.addElement("HR_NOM");
		}else if(ecran.trim().equalsIgnoreCase("producteur")){
			strSql = "Select * from produ00001 where PR_NOM like ?";
			vec.addElement("PR_NOM");
		}
		//Instanciation de l'objet générique de traitement des listes
 		TraitementListe tListe = new TraitementListe();
 		//Appel de la méthode de récupération des données
		Liste resultat = tListe.???????
		//Alimentation d'un attribut dans la requête avec l'objet résultat
		req.???????????
		//Redirection de la requête vers le bon jsp
		//nom du JSP = nom de l'écran
		getServletContext().???????
	} catch (Exception e) {
	}
}

/**
 * ServletListe constructor comment.
 */
public ServletListe() {
	super();
}
}
 
    
    Corrigé
    
package formation.mvc.servlet;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import formation.mvc.bean.*;
import formation.mvc.resultat.*;
import java.util.*;
/**
 * Insert the type's description here.
 * Creation date: (24/11/2002 17:08:26)
 * @author: Administrator
 */
public class ServletListe extends HttpServlet {

/**
 * doGet method comment.
 */
public void doGet(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	doPost(req,res);
}
/**
 * doPost method comment.
 */
public void doPost(HttpServletRequest req, HttpServletResponse res) 
	throws ServletException, IOException {
	try {
		HttpSession session = req.getSession(true);
		//Lecture des paramètres
		Enumeration enum = req.getParameterNames();
		Hashtable params = new Hashtable();
		while (enum.hasMoreElements()) {
			String nom = (String)enum.nextElement();
			String valeur = (String)req.getParameter(nom);
			params.put(nom,valeur);
		}
		String strSql = null;
		Vector vec = new Vector();
		//Récupération de l'écran à traiter
		String ecran = req.getParameter("ecran");
		if(ecran.trim().equalsIgnoreCase("vins")){
			strSql = "Select * from vins where VIN_NOM like ?";
			vec.addElement("VIN_NOM");
		}else if(ecran.trim().equalsIgnoreCase("hotelresto")){
			strSql = "Select * from hotelresto where HR_NOM like ?";
			vec.addElement("HR_NOM");
		}else if(ecran.trim().equalsIgnoreCase("producteur")){
			strSql = "Select * from producteurs where PR_NOM like ?";
			vec.addElement("PR_NOM");
		}
 		TraitementListe tListe = new TraitementListe();
		Liste resultat = tListe.getDonnees(params,strSql,vec);
		req.setAttribute(ecran,resultat);
		getServletContext().getRequestDispatcher("/formation/"+ecran+"liste.jsp")
			.forward(req,res);
	} catch (Exception e) {
	}
}

/**
 * ServletListe constructor comment.
 */
public ServletListe() {
	super();
}
}

|

JSP vinsliste :  
    
<html>
<head>
<title>Gestion des vins</title>
</head>

<jsp:useBean class="formation.mvc.resultat.Liste" id="vins" scope="request" />

<body>

<p>Liste des vins</p>
<form method="POST" action="/servlet/formation.mvc.servlet.ServletListe">

<input type="hidden" name="ecran" value="vins">

<input type="hidden" name="nbEnregLus" value="<%=vins.getNbEnregLus()%>">
<input type="hidden" name="nbEnregAff" value="<%=vins.getNbEnregAff()%>">
<%
String valeur = (String)vins.getListeCritere().get("VIN_NOM");
%>
<p>
Nom du vin : <input type="text" name="VIN_NOM" size="20" value="<%=valeur%>"><br>
<input type="submit" value="Lire" name="lire">
<%if(vins.getNbEnregLus()%vins.getNbiteration() ==0){%>
<input type="submit" value="Suivant" name="suivant">
<%}%>
<%if(vins.getNbEnregLus()>vins.getNbiteration() ){%>
<input type="submit" value="Précédent" name="precedent"> 
<%}%>
</p>
</form>
<table border="1">
<tr bgcolor="#FFFFC6">
<th>Code</th>
<th>Nom</th>
<th>Cépage</th>
<th>Etiquette</th>
</tr>
<%
int vecLen = vins.getListeEnregistrement().size();
for(int i=0;i<vecLen;i++){
java.util.Hashtable enreg = (java.util.Hashtable)vins.getListeEnregistrement().elementAt(i);

if((i%2)==0){%>
<tr bgcolor="rgb(208,232,246)">
<%}else{%> 
<tr>
<%}%>
<td><%=(String)enreg.get("VIN_CODE")%>&nbsp;</td>
<td><%=(String)enreg.get("VIN_NOM")%>&nbsp;</td>
<td><%=(String)enreg.get("VIN_CEPAGE1")%>&nbsp;</td>
<td><%=(String)enreg.get("VIN_ETIQUETTE")%>&nbsp;</td>
</tr>
<%}//end for%>


</table>

</body>
</html>


JSP producteurliste :


    
<html>
<head>
<title>Gestion des producteurs</title>
</head>

<jsp:useBean class="formation.mvc.resultat.Liste" id="producteur" scope="request" />

<body>

<p>Liste des producteurs</p>
<form method="POST" action="/servlet/formation.mvc.servlet.ServletListe">

<input type="hidden" name="ecran" value="producteur">

<input type="hidden" name="nbEnregLus" value="<%=producteur.getNbEnregLus()%>">
<input type="hidden" name="nbEnregAff" value="<%=producteur.getNbEnregAff()%>">
<%
String valeur = (String)producteur.getListeCritere().get("PR_NOM");
%>
<p>
Nom des producteurs: <input type="text" name="PR_NOM" size="20" value="<%=valeur%>"><br>
<input type="submit" value="Lire" name="lire">
<%if(producteur.getNbEnregLus()%producteur.getNbiteration() ==0){%>
<input type="submit" value="Suivant" name="suivant">
<%}%>
<%if(producteur.getNbEnregLus()>producteur.getNbiteration() ){%>
<input type="submit" value="Précédent" name="precedent"> 
<%}%>
</p>
</form>
<table border="1">
<tr bgcolor="#FFFFC6">
<th>Code</th>
<th>Nom</th>
<th>Code postal</th>
<th>Commune</th>
</tr>
<%
int vecLen = producteur.getListeEnregistrement().size();
for(int i=0;i<vecLen;i++){
java.util.Hashtable enreg = (java.util.Hashtable)producteur.getListeEnregistrement().elementAt(i);

if((i%2)==0){%>
<tr bgcolor="rgb(208,232,246)">
<%}else{%> 
<tr>
<%}%>
<td><%=(String)enreg.get("PR_CODE")%>&nbsp;</td>
<td><%=(String)enreg.get("PR_NOM")%>&nbsp;</td>
<td><%=(String)enreg.get("PR_CDPST")%>&nbsp;</td>
<td><%=(String)enreg.get("PR_COMMUNE")%>&nbsp;</td>
</tr>
<%}//end for%>


</table>

</body>
</html>


JSP hotelrestoliste :


    
<html>
<head>
<title>Gestion des hotelresto</title>
</head>

<jsp:useBean class="formation.mvc.resultat.Liste" id="hotelresto" scope="request" />

<body>

<p>Liste des hôtels restaurants</p>
<form method="POST" action="/servlet/formation.mvc.servlet.ServletListe">

<input type="hidden" name="ecran" value="hotelresto">

<input type="hidden" name="nbEnregLus" value="<%=hotelresto.getNbEnregLus()%>">
<input type="hidden" name="nbEnregAff" value="<%=hotelresto.getNbEnregAff()%>">
<%
String valeur = (String)hotelresto.getListeCritere().get("HR_NOM");
%>
<p>
Nom des hôtels restaurants: <input type="text" name="HR_NOM" size="20" value="<%=valeur%>"><br>
<input type="submit" value="Lire" name="lire">
<%if(hotelresto.getNbEnregLus()%hotelresto.getNbiteration() ==0){%>
<input type="submit" value="Suivant" name="suivant">
<%}%>
<%if(hotelresto.getNbEnregLus()>hotelresto.getNbiteration() ){%>
<input type="submit" value="Précédent" name="precedent"> 
<%}%>
</p>
</form>
<table border="1">
<tr bgcolor="#FFFFC6">
<th>Code</th>
<th>Nom</th>
<th>Type</th>
<th>Code postal</th>
<th>Commune</th>
<th>Tarif</th>
</tr>
<%
int vecLen = hotelresto.getListeEnregistrement().size();
for(int i=0;i<vecLen;i++){
java.util.Hashtable enreg = (java.util.Hashtable)hotelresto.getListeEnregistrement().elementAt(i);

if((i%2)==0){%>
<tr bgcolor="rgb(208,232,246)">
<%}else{%> 
<tr>
<%}%>
<td><%=(String)enreg.get("HR_CODE")%>&nbsp;</td>
<td><%=(String)enreg.get("HR_NOM")%>&nbsp;</td>
<td><%=(String)enreg.get("HR_TYPE")%>&nbsp;</td>
<td><%=(String)enreg.get("HR_CDPST")%>&nbsp;</td>
<td><%=(String)enreg.get("HR_COMMUNE")%>&nbsp;</td>
<td><%=(String)enreg.get("HR_PRIX")%>&nbsp;</td>
</tr>
<%}//end for%>


</table>

</body>
</html>

 

©AF400