Grosse MàJ

This commit is contained in:
olivier
2008-11-25 22:11:16 +01:00
parent 53195fdfcd
commit 3e719157ea
2980 changed files with 343846 additions and 0 deletions

View File

@ -0,0 +1,78 @@
public class Article
{
private String ref = "";
private String categ = "";
private String marque = "";
private String modele = "";
private double prix = 0;
private String photo = "";
private String description = "";
private int quantite = 0;
public String getRef()
{
return this.ref;
}
public String getCateg()
{
return this.categ;
}
public String getMarque()
{
return this.marque;
}
public String getModele()
{
return this.modele;
}
public double getPrix()
{
return this.prix;
}
public String getPhoto()
{
return this.photo;
}
public String getDescription()
{
return this.description;
}
public void setRef(String ref)
{
this.ref = ref;
}
public void setCateg(String categ)
{
this.categ = categ;
}
public void setMarque(String marque)
{
this.marque = marque;
}
public void setModele(String modele)
{
this.modele = modele;
}
public void setPrix(double prix)
{
this.prix = prix;
}
public void setPhoto(String photo)
{
this.photo = photo;
}
public void setDescription(String description)
{
this.description = description;
}
public int getQuantite()
{
return this.quantite;
}
public void setQuantite(int quantite)
{
this.quantite = quantite;
}
}

View File

@ -0,0 +1,25 @@
public class ArticlePanier
{
private String ref = "";
private int quantite = 0;
public String getRef()
{
return this.ref;
}
public void setRef(String ref)
{
this.ref = ref;
}
public int getQuantite()
{
return this.quantite;
}
public void setQuantite(int quantite)
{
this.quantite = quantite;
}
}

View File

@ -0,0 +1,35 @@
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
import java.util.Vector;
import com.articles.Article;
public class ArticlesTag
extends SimpleTagSupport
{
private String var;
public void doTag()
throws JspException, IOException
{
Vector<Article> vArts = (Vector<Article>)getJspContext().getAttribute("articles");
if (vArts == null)
{
getJspContext().setAttribute(this.var, new Article() );
getJspBody().invoke(null);
return;
}
for (int i=0; i<vArts.size(); i++)
{
getJspContext().setAttribute(this.var, (Article)vArts.get(i) );
getJspBody().invoke(null);
}
}
public void setVar( String var )
{
this.var = var;
}
}

View File

@ -0,0 +1,357 @@
import java.sql.*;
import java.util.Vector;
enum OperationBDD
{
OP_BDD_SELECTION,
OP_BDD_CREER_TABLE,
OP_BDD_SUPPR_TABLE
}
public class GestionConnexion
{
private ParametresConnexion paramsConn;
private Connection connection = null;
private Statement statement = null;
private String requeteSQL = "";
private ResultSet resultSet = null;
private Vector<String> vs_erreurs = null;
private Vector<String> vs_anomalies = null;
public GestionConnexion()
throws ClassNotFoundException, Exception
{
this.statement = null;
this.resultSet = null;
this.requeteSQL = "";
this.paramsConn = new ParametresConnexion();
this.vs_erreurs = new Vector<String>();
this.vs_anomalies = new Vector<String>();
try
{
Class.forName(ParametresConnexion.CLASSE).newInstance();
}
catch (ClassNotFoundException ex)
{
throw ex;
}
catch (Exception ex)
{
throw ex;
}
}
public void ouvrir(ParametresConnexion params)
{
if (params == null)
throw new NullPointerException();
this.paramsConn.CopierDepuis(params);
this.ouvrir();
}
public void ouvrir()
{
try
{
this.fermerConnexion();
this.connection = DriverManager.getConnection(this.paramsConn.getUrl(),
this.paramsConn.Utilisateur, this.paramsConn.Pwd);
this.traiterWarning(this.connection.getWarnings());
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
this.fermerConnexion();
}
}
public boolean estOuverte()
{
boolean bOuverte = false;
try
{
if (this.connection != null)
bOuverte = !this.connection.isClosed();
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
return bOuverte;
}
public void fermerRessourcesRequete()
{
try
{
if (this.resultSet != null)
{
this.resultSet.close();
this.resultSet = null;
}
if (this.statement != null)
{
this.statement.close();
this.statement = null;
}
this.requeteSQL = "";
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
}
public void fermerConnexion()
{
try
{
this.fermerRessourcesRequete();
if (this.connection != null)
{
this.connection.close();
this.connection = null;
}
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
}
public boolean lancerRequeteSelection(String query)
{
boolean res = true;
try
{
if (this.connection != null)
{
this.fermerRessourcesRequete();
this.statement = this.connection.createStatement();
this.traiterWarning(this.statement.getWarnings());
this.resultSet = this.statement.executeQuery(query);
this.traiterWarning(this.resultSet.getWarnings());
this.requeteSQL = query;
}
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
this.fermerRessourcesRequete();
res = false;
}
return res;
}
public int lancerRequeteModifBDD(String query)
{
int res = 0;
try
{
if (this.connection != null)
{
this.fermerRessourcesRequete();
this.statement = this.connection.createStatement();
res = this.statement.executeUpdate(query);
this.traiterWarning(this.statement.getWarnings());
this.requeteSQL = query;
}
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
this.fermerRessourcesRequete();
res = -1;
}
return res;
}
public ParametresConnexion getParametresConnexion()
{
return new ParametresConnexion(this.paramsConn);
}
public String getRequeteSQL()
{
return this.requeteSQL;
}
public Vector<String> getInfosConnexion()
{
Vector<String> vs_infosConn = new Vector<String>();
DatabaseMetaData dmd;
try
{
if (this.estOuverte())
{
vs_infosConn.add("Etat de la connexion : ouverte");
vs_infosConn.add("------------------------------");
dmd = this.connection.getMetaData();
vs_infosConn.add("Connexion : " + dmd.getURL());
vs_infosConn.add("Driver : " + dmd.getDriverName());
vs_infosConn.add("Version : " + dmd.getDriverVersion());
}
else
{
vs_infosConn.add("Etat de la connexion : ferm<72>e");
vs_infosConn.add("------------------------------");
vs_infosConn.add("Connexion : " + this.paramsConn.getUrl());
vs_infosConn.add("Utilisateur : " + this.paramsConn.Utilisateur);
vs_infosConn.add("Mot de passe : " + this.paramsConn.Pwd.length() + " caract<63>re(s)");
}
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
return vs_infosConn;
}
public Vector<String> getNomsColonnes()
{
Vector<String> vs_cols = new Vector<String>();
ResultSetMetaData rsmd;
try
{
if (this.resultSet != null)
{
rsmd = this.resultSet.getMetaData();
int nbrCols = rsmd.getColumnCount();
for (int idCol = 1; idCol <= nbrCols; idCol++)
if (rsmd.isSearchable(idCol))
vs_cols.add(rsmd.getColumnName(idCol));
}
else if (this.statement == null)
this.vs_anomalies.add("Vous n'avez pas encore lanc<6E> la requ<71>te!!");
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
return vs_cols;
}
public Vector<Vector<Object>> getDataVector()
{
Vector<Vector<Object>> v_datas = new Vector<Vector<Object>>();
ResultSetMetaData rsmd;
try
{
rsmd = this.resultSet.getMetaData();
if (rsmd.getColumnCount() > 0)
{
while (this.resultSet.next())
{
Vector<Object> vo_ligne = new Vector<Object>();
for (int idCol = 1; idCol <= rsmd.getColumnCount(); idCol++)
vo_ligne.add(this.resultSet.getObject(idCol));
v_datas.add(vo_ligne);
}
}
if (v_datas.isEmpty())
this.vs_anomalies.add("Aucune donn<6E>e trouv<75>e!!");
}
catch (SQLException ex)
{
this.traiterSQLException(ex);
}
return v_datas;
}
public void traiterSQLException(SQLException ex)
{
String str_ex;
str_ex = "********* SQLException *********\n";
while (ex != null)
{
str_ex = "SQLState : " + ex.getSQLState() + "\n";
str_ex += "Message : " + ex.getMessage() + "\n";
str_ex += "------------------------------\n";
this.vs_erreurs.add(str_ex);
ex = ex.getNextException();
}
}
public void traiterWarning(SQLWarning warn)
{
String str_an;
str_an = "********* SQLWarning *********\n";
while (warn != null)
{
str_an = "SQLState : " + warn.getSQLState() + "\n";
str_an += "Message : " + warn.getMessage() + "\n";
str_an += "------------------------------\n";
this.vs_anomalies.add(str_an);
warn = warn.getNextWarning();
}
}
public Vector<String> getErreurs()
{
return new Vector<String>(this.vs_erreurs);
}
public Vector<String> getAnomalies()
{
return new Vector<String>(this.vs_anomalies);
}
public void effaceErreurs()
{
this.vs_erreurs.clear();
}
public void effaceAnomalies()
{
this.vs_anomalies.clear();
}
}

View File

@ -0,0 +1,84 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.Vector;
import com.articles.Article;
import com.articles.ArticlePanier;
import com.gestionnaires.Erreur;
import com.gestionnaires.GestionnairePanier;
public class ListeArticles
extends HttpServlet
{
com.gestionnaires.GestionnaireArticles gestArts = null;
private void traiteRequeteHttp(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
String sAction;
String sInfoArtRef;
String sPageAffichage;
Vector<Article> vArts = new Vector<Article>();
Article tmpArt = null;
sAction = request.getParameter("action");
if (sAction.equals("info"))
{
sInfoArtRef = request.getParameter("artRef");
tmpArt = new Article();
tmpArt.setRef(sInfoArtRef);
request.setAttribute("art", tmpArt);
sPageAffichage = "/infos.jsp";
}
else
{
for (int i=0; i<5; i++)
{
tmpArt = new Article();
tmpArt.setRef("refArt"+i);
tmpArt.setCateg("cat"+i);
tmpArt.setDescription("desc"+1);
vArts.add(tmpArt);
}
if (!vArts.isEmpty())
{
request.setAttribute("articles", vArts);
sPageAffichage = "/listeArticles.jsp";
}
else
{
Vector<Erreur> vErrs = new Vector<Erreur>();
vErrs.add(new Erreur("Articles non disponibles"));
request.setAttribute("erreurs", vErrs);
sPageAffichage = "/erreurs.jsp";
}
}
ServletContext ctx = getServletContext();
RequestDispatcher rd = ctx.getRequestDispatcher(sPageAffichage);
rd.forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.traiteRequeteHttp(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.traiteRequeteHttp(request, response);
}
public String getServletInfo() {
return "Gestion du panier";
}
}

View File

@ -0,0 +1,18 @@
package MesHaricots;
public class utilisateur {
private String identifiant;
public utilisateur() {
}
public String getId() {
return identifiant;
}
public void setId(String id) {
this.identifiant = id;
}
}

View File

@ -0,0 +1,93 @@
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.lang.*;
import java.util.Vector;
import com.articles.Article;
import com.articles.ArticlePanier;
import com.gestionnaires.Erreur;
import com.gestionnaires.GestionnairePanier;
public class Panier
extends HttpServlet
{
com.gestionnaires.GestionnaireArticles gestArts = null;
private void traiteRequeteHttp(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
HttpSession session = request.getSession(true);
Vector<ArticlePanier> vArtsPan = null;
Vector<Article> vArts = new Vector<Article>();
Article tmpArt = null;
String sAction;
String sPageAffichage;
GestionnairePanier panier = (GestionnairePanier)session.getAttribute("caddy");
if ( panier == null )
{
panier = new GestionnairePanier();
session.setAttribute("caddy", panier) ;
}
sAction = request.getParameter("action");
if (sAction == null)
{
;
}
else if (sAction.equals("add"))
{
panier.ajouterAchat(request.getParameter("artRef"), Integer.parseInt(request.getParameter("artQuant")));
}
else if (sAction.equals("del"))
{
panier.enleverAchat(request.getParameter("artRef"));
}
vArtsPan = panier.donneContenu();
for (int i=0; i<vArtsPan.size(); i++)
{
tmpArt = new Article();
tmpArt.setRef(vArtsPan.get(i).getRef());
tmpArt.setQuantite(vArtsPan.get(i).getQuantite());
tmpArt.setCateg("cat"+i);
tmpArt.setDescription("desc"+1);
vArts.add(tmpArt);
}
if (!vArts.isEmpty())
{
request.setAttribute("articles", vArts);
sPageAffichage = "/contenuPanier.jsp";
}
else
{
sPageAffichage = "/panierVide.jsp";
}
ServletContext ctx = getServletContext();
RequestDispatcher rd = ctx.getRequestDispatcher(sPageAffichage);
rd.forward(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.traiteRequeteHttp(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.traiteRequeteHttp(request, response);
}
public String getServletInfo() {
return "Gestion du panier";
}
}

View File

@ -0,0 +1,42 @@
public class ParametresConnexion
{
public String Serveur = "http://canette.u-strasbg.fr";
public String Port = "3001";
public String Base = "v920";
public String Utilisateur = "dut";
public String Pwd = "dut";
public static final String CLASSE = "oracle.jdbc.driver.OracleDriver";
public static final String URL_BASE = "jdbc:oracle:thin:";
public ParametresConnexion( ParametresConnexion params )
{
this.CopierDepuis(params);
}
public ParametresConnexion(String serveur, String port, String base,
String utilisateur, String pwd)
{
this.Serveur = serveur;
this.Port = port;
this.Base = base;
this.Utilisateur = utilisateur;
this.Pwd = pwd;
}
public String getUrl()
{
return ParametresConnexion.URL_BASE + "@" + this.Serveur + ":" + this.Port + ":" + this.Base;
}
public void CopierDepuis( ParametresConnexion params )
{
this.Serveur = params.Serveur;
this.Port = params.Port;
this.Base = params.Base;
this.Utilisateur = params.Utilisateur;
this.Pwd = params.Pwd;
}
}

View File

@ -0,0 +1,54 @@
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import MesHaricots.utilisateur;
/**
* * Servlet implementation class for Servlet: ServTest
* *
* */
public class ServletController extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {
static final long serialVersionUID = 1L;
/* (non-Java-doc)
* * @see javax.servlet.http.HttpServlet#HttpServlet()
* */
public ServletController() {
super();
}
/* (non-Java-doc)
* * @see javax.servlet.http.HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
* */
protected void doGet(HttpServletRequest requete, HttpServletResponse reponse)
throws ServletException, IOException {
String jspPage = "/vues/loginForm.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(jspPage);
rd.forward(requete,reponse);
}
/* (non-Java-doc)
* * @see javax.servlet.http.HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
* */
protected void doPost(HttpServletRequest requete, HttpServletResponse reponse)
throws ServletException, IOException {
String identifiant = requete.getParameter("id");
String jspPage = "/vues/salut.jsp";
ServletContext sc = getServletContext();
RequestDispatcher rd = sc.getRequestDispatcher(jspPage);
utilisateur user = new utilisateur();
user.setId(identifiant);
requete.setAttribute("monUtilisateur", user);
rd.forward(requete,reponse);
// TODO Auto-generated method stub
}
}

View File

@ -0,0 +1,14 @@
package balise;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.tagext.SimpleTagSupport;
import java.io.IOException;
/**
* * * SimpleTag handler that prints "Hello, world!"
* * */
public class afficheutilisateur extends SimpleTagSupport {
public void doTag() throws JspException, IOException {
getJspContext().getOut().write( "Bonjour !" );
}
}