Commit 07bd1cd8 authored by Lefebvre michael's avatar Lefebvre michael

tp jsp

parent 95c67880
......@@ -13,7 +13,10 @@
</head>
<body>
<div id="contenu">
<form method="POST" action="doCheckLogin.jsp">
<fieldset id="login">
<legend >identifiant</legend>
<p class="double">
<label for="f1-nom">Nom : </label>
<input type="text" id="f1-nom" name="nom" value="${login.nom}">
......@@ -29,7 +32,7 @@
<input type="submit" name="ok" value="Envoyer">
</p>
</fieldset>
</form>
......
......@@ -13,7 +13,10 @@
</head>
<body>
<div id="contenu">
<form method="POST" action="doCheckLogin.jsp">
<fieldset id="login">
<legend >identifiant</legend>
<p class="double">
<label for="f1-nom">Nom : </label>
<input type="text" id="f1-nom" name="nom" value="${login.nom}">
......@@ -29,7 +32,7 @@
<input type="submit" name="ok" value="Envoyer">
</p>
</fieldset>
</form>
......
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="web" name="Web">
<configuration>
<descriptors>
<deploymentDescriptor name="web.xml" url="file://$MODULE_DIR$/web/WEB-INF/web.xml" />
</descriptors>
<webroots>
<root url="file://$MODULE_DIR$/web" relative="/" />
</webroots>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="PROVIDED" name="Tomcat 9.0.311" level="application_server_libraries" />
<orderEntry type="library" name="mysql-connector-java-5.1.6-bin" level="project" />
<orderEntry type="library" name="jstl-api-1.2" level="project" />
</component>
</module>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 11:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=pages/form_probleme.jsp"/>
</head>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 14:17
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="beans.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="techSupportBean"
scope="session"
type="beans.ControlBean"/>
<hr/>
Utilisateur actuel :
<%-- A la boomer --%>
<jsp:getProperty name="techSupportBean" property="*"/>
<%-- a la millenium --%>
${sessionScope.techSupportBean.lastname}
<hr/>
Entreprise XYZ, Service Client au 1.800.xyz.corp <br>
<c:remove scope="session" var="techSupportBean"/>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 12:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="beans.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- CREATION ET INIT DU COMPOSANT METIER --%>
<jsp:useBean id="techSupportBean"
scope="session"
class="beans.ControlBean">
<jsp:setProperty name="techSupportBean" property="*"/>
</jsp:useBean>
<%-- REGLE METIER : ENREGISTREMENT INCIDENT --%>
<%
techSupportBean.registerSupportRequest();
%>
<%-- REGLE METIER LE CLIENT EXISTE T-IL EN BD ? isregistered--%>
<c:if test="${techSupportBean.registered}">
<jsp:forward page="response.jsp"/>
</c:if>
<jsp:forward page="regForm.jsp"/>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 13:21
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<html>
<head>
<title>Entreprise XYZ, Service IT</title>
</head>
<body>
<h1>Support technique</h1>
<p>
Nous sommes désolé, une erreur s'est produite lors du traiment de votre requête.
</p>
<p>
Le problème rencontré est <%=exception%>
</p>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 12:44
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Support technique</title>
</head>
<body>
<div id="formulaire">
<form method="POST" action="control.jsp" id="form_prob" >
<fieldset>
<legend>problème technique</legend>
<label id="email">E-mail</label>
<input type="email" name="email" id="pb_email">
<br>
<label >Logiciel</label>
<select name="software" id="pb_software">
<option value="microsoftAcces">MicroSoft Acces</option>
<option value="intellij">Intellij</option>
<option value="dbeaver">BDeaver</option>
<option value="phpmyadmin">PHP my admin</option>
<option value="eclipse">Eclipse</option>
</select>
<br>
<select name="os" id="pb_os">
<option value="ubuntu">Ubuntu</option>
<option value="windows10">Windows 10</option>
<option value="windows8">Windows 8</option>
<option value="windows7">Windows 7</option>
<option value="mac">Mac</option>
</select>
<label >Problème</label>
<input type="text" id="problem" name="problem">
<br>
<input type="submit" name="envoie" value="Envoyer">
</fieldset>
</form>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 13:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Enregistrement</title>
</head>
<body>
<div id="formulaire">
<form method="POST" action="register.jsp" id="form_prob" >
<fieldset>
<legend>Coordonées</legend>
<label >nom</label>
<input type="text" name="firstname" id="fname">
<br>
<label >prenom</label>
<input type="text" name="lastname" id="lname">
<br>
<label >telphone</label>
<input type="text" name="phoneNumber" id="phoneNumber">
<br>
<input type="submit" value="Enregistrer" name="enregistrer">
</fieldset>
</form>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 14:06
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" errorPage="error.jsp" import="beans.*" %>
<%-- Locallisation du composant metier --%>
<jsp:useBean id="techSupportBean"
scope="session"
class="beans.ControlBean">
</jsp:useBean>
<%-- mise a joiur des 3 champs lnmae, fname, phone du composant metier --%>
<jsp:setProperty name="techSupportBean" property="*"/>
<%-- REGLE METIER : ENREGISTREMENT CLIENT --%>
<% techSupportBean.registerCustomer();%>
<%-- cinematique --%>
<jsp:forward page="response.jsp"/>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 13:23
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Reponse du service client</title>
</head>
<body>
<h1>Demande de support technique reçu</h1>
<p>Merci de votre demande</p>
<p>Celle-ci à été enregistrée. Une réponse sera apportée dans trois jours ouvrables.</p>
</body>
<footer>
<jsp:include page="banner.jsp"/>
</footer>
</html>
package beans;
import db_util.MyConnection;
import java.io.Serializable;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
public class ControlBean implements Serializable {
private static final long serialVersionUID = 1L;
//CORRESPOND AU PARAMETRE DES DEUX FORMULAIRES HTML
//FORMULAIRE ENREGISTREMENT INCIDENT
private String email;
private String software;
private String os;
private String problem;
//FORMAULAIRE ENREGISTREMENT CLIENT
private String firstname;
private String lastname;
private String phoneNumber;
//REQUETES
private static final String insertStatementStr =
"INSERT INTO CUSTOMERS VALUES(?, ?, ?, ? )";
private static final String selectCustomerStr =
"SELECT fname, lname, phone " +
" FROM CUSTOMERS " +
" WHERE LOWER(email) = ? ";
private static final String insertSuppRequestStr =
" INSERT INTO SUPP_REQUESTS(email, software, os, problem) " +
" VALUES(?, ?, ?, ? )";
public ControlBean(){
}
//GETTER SETTER
public static long getSerialVersionUID() {
return serialVersionUID;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email.toLowerCase();
}
public String getSoftware() {
return software;
}
public void setSoftware(String software) {
this.software = software;
}
public String getOs() {
return os;
}
public void setOs(String os) {
this.os = os;
}
public String getProblem() {
return problem;
}
public void setProblem(String problem) {
this.problem = problem;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public String getPhoneNumber() {
return phoneNumber;
}
public void setPhoneNumber(String phoneNumber) {
this.phoneNumber = phoneNumber;
}
//REGLES METIER
//ACCES A LA BASE DE DONNEES
public void registerSupportRequest() throws SQLException {
PreparedStatement insertStatement =
MyConnection.getINSTANCE().prepareStatement(insertSuppRequestStr);
insertStatement.setString(1,email.toLowerCase());
insertStatement.setString(2,software);
insertStatement.setString(3,os);
insertStatement.setString(4,problem);
insertStatement.executeUpdate();
//on verifie si le client est enregistré ou non
PreparedStatement selectStatement = MyConnection.getINSTANCE().prepareStatement(selectCustomerStr);
selectStatement.setString(1,this.email.toLowerCase());
ResultSet rs = selectStatement.executeQuery();
if (rs.next()){
System.out.println("le client est enregistre");
this.setFirstname((rs.getString("fname")));
this.setLastname(rs.getString("lname"));
this.setPhoneNumber(rs.getString("phone"));
//Le client est enregistre on va a la page reponse
this.registered = true;
}else{
//le client n'est pas encore enregistre on doit aller au formulaire
this.registered = false;
}
}
public void registerCustomer() throws SQLException{
PreparedStatement insertStatement = null;
try {
MyConnection.getINSTANCE().setAutoCommit(false);
insertStatement = MyConnection.getINSTANCE().prepareStatement(insertStatementStr);
insertStatement.setString(1,email.toLowerCase());
insertStatement.setString(2,firstname);
insertStatement.setString(3,lastname);
insertStatement.setString(4,phoneNumber);
insertStatement.executeUpdate();
MyConnection.getINSTANCE().commit();
}catch (SQLException ex){
MyConnection.getINSTANCE().rollback();
throw ex;
}
}
private boolean registered;
public boolean isRegistered(){return registered;}
public static void main(String[] args) {
ControlBean cb = new ControlBean();
cb.setEmail("test@test.fr");
cb.setOs("ubuntu");
cb.setSoftware("intellij");
cb.setProblem("merde");
}
}
package db_util;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class MyConnection {
//IDENTIFICATION BASE DE DONNEES
private final static String URL="jdbc:mysql://localhost:3306/support_technique";
private final static String USER= "michael";
private final static String PW = "mdppopmichael";
//SINGLETON : DECLARATION
private static Connection INSTANCE = null;
//SINGLETON : INITIALISATION
static{
try{
INSTANCE = DriverManager.getConnection(URL,USER,PW);
}catch (SQLException e){
e.printStackTrace();
}
}
//SIBGLETON : ACCESSEUR
public static java.sql.Connection getINSTANCE(){
return INSTANCE;
}
}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">
</web-app>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 11:11
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<meta http-equiv="Refresh" content="0; URL=pages/form_probleme.jsp"/>
</head>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 14:17
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="beans.*"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<jsp:useBean id="techSupportBean"
scope="session"
type="beans.ControlBean"/>
<hr/>
Utilisateur actuel :
<%-- A la boomer --%>
<jsp:getProperty name="techSupportBean" property="*"/>
<%-- a la millenium --%>
${sessionScope.techSupportBean.lastname}
<hr/>
Entreprise XYZ, Service Client au 1.800.xyz.corp <br>
<c:remove scope="session" var="techSupportBean"/>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 12:58
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" import="beans.*" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%-- CREATION ET INIT DU COMPOSANT METIER --%>
<jsp:useBean id="techSupportBean"
scope="session"
class="beans.ControlBean">
<jsp:setProperty name="techSupportBean" property="*"/>
</jsp:useBean>
<%-- REGLE METIER : ENREGISTREMENT INCIDENT --%>
<%
techSupportBean.registerSupportRequest();
%>
<%-- REGLE METIER LE CLIENT EXISTE T-IL EN BD ? isregistered--%>
<c:if test="${techSupportBean.registered}">
<jsp:forward page="response.jsp"/>
</c:if>
<jsp:forward page="regForm.jsp"/>
\ No newline at end of file
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 13:21
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isErrorPage="true" %>
<html>
<head>
<title>Entreprise XYZ, Service IT</title>
</head>
<body>
<h1>Support technique</h1>
<p>
Nous sommes désolé, une erreur s'est produite lors du traiment de votre requête.
</p>
<p>
Le problème rencontré est <%=exception%>
</p>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 12:44
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Support technique</title>
</head>
<body>
<div id="formulaire">
<form method="POST" action="control.jsp" id="form_prob" >
<fieldset>
<legend>problème technique</legend>
<label id="email">E-mail</label>
<input type="email" name="email" id="pb_email">
<br>
<label >Logiciel</label>
<select name="software" id="pb_software">
<option value="microsoftAcces">MicroSoft Acces</option>
<option value="intellij">Intellij</option>
<option value="dbeaver">BDeaver</option>
<option value="phpmyadmin">PHP my admin</option>
<option value="eclipse">Eclipse</option>
</select>
<br>
<select name="os" id="pb_os">
<option value="ubuntu">Ubuntu</option>
<option value="windows10">Windows 10</option>
<option value="windows8">Windows 8</option>
<option value="windows7">Windows 7</option>
<option value="mac">Mac</option>
</select>
<label >Problème</label>
<input type="text" id="problem" name="problem">
<br>
<input type="submit" name="envoie" value="Envoyer">
</fieldset>
</form>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 20/02/2020
Time: 13:22
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>