1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
| package com.test.essai2;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@SuppressWarnings("serial")
public class exemple extends HttpServlet {
private static final String CONTENT_TYPE = "text/html";
//Initialiser les variables globales
public void init() throws ServletException {
}
//Traiter la requête HTTP Get
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>exemple</title></head>");
out.println("<body bgcolor=\"#ffffff\">");
out.println("<p><img src=" + "http://127.0.0.1/acceuil.png" + "></p>");
out.println("<p>Réponse serveur BSD table annonce</p>");
out.println("<p> </p>");
//creation de l'objet pour connect BSD
Connexion_BSD toto = new Connexion_BSD("SELECT * FROM annonce ORDER BY ref_identification");
int i, j;
if (toto.if_connect) {
out.println("<p><TABLE align=left border=1>");
for (i = 0; i < toto.resultat.length; i++) {
out.println("<TR>");
for (j = 0; j < toto.nombre_col; j++) {
out.println("<TD bgcolor=#FFCC99><font color=#0000FF size=1 face=Verdana, Arial, Helvetica, sans-serif>" +
toto.resultat[i][j] + "</font></TD>");
}
out.println("</TR>");
}
out.println("</TABLE></p>");
}
else out.println("<P>connexion impossible avec le serveur de base des données</P>");
out.println("</body></html>");
}
//Nettoyer les ressources
public void destroy() {
}
@Override
protected void doPost(HttpServletRequest arg0, HttpServletResponse arg1) throws ServletException, IOException {
// TODO Auto-generated method stub
super.doGet(arg0, arg1);
}
} |
Partager