Commit 5a6bd4dc authored by Lefebvre michael's avatar Lefebvre michael

projet cinema servelet

parent 7b26ec2d
<?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: 24/02/2020
Time: 14:35
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=process?action=init"/>
</head>
<body>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:20
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach var="film" items="${ensFilms}">
<tr>
<td>${film.titre}</td>
<td>${film.nomRealisateur}</td>
<td>${film.nomActeur}</td>
</tr>
</c:forEach>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 16:17
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Films choisi</h1>
<c:forEach var="choix" items="${ensChoix}">
${choix.value.titre}
<br>
</c:forEach>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
Fils du genre ${genre.nature}
<br>
<form action="process?action=choix" method="POST">
<table>
<thead>
<tr>
<th>Titre</th>
<th>Réalisateur</th>
<th>Acteur</th>
<th>Choix</th>
</tr>
</thead>
<tbody>
<c:forEach var="film" items="${ensFilms}">
<tr>
<td>${film.titre}</td>
<td>${film.nomRealisateur}</td>
<td>${film.nomActeur}</td>
<td><input type="checkbox" name="choix" value="${film.nfilm}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="votre panier">
</form>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:14
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Vue choix</title>
</head>
<body>
<form method="POST" action="process?action=filmsDuGenre">
<fieldset>
<legend> choix d'un genre</legend>
Genre:
<select name="genre">
<c:forEach var="genre" items="${ensGenres}">
<option value="${genre.ngenre}">
${genre.nature}
</option>
</c:forEach>
</select>
<input type="submit" value="envoie">
</fieldset>
</form>
</body>
</html>
<?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
package control;
import dao.CinemaDAO;
import dto.FilmDTO;
import dto.GenreDTO;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.*;
import java.io.IOException;
@WebServlet("/process")
public class ControlServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRquest(request,response);
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
processRquest(request, response);
}
//navigation
private void forward(String url, HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
RequestDispatcher rd = request.getRequestDispatcher(url);
rd.forward(request, response);
}
//routage
private void processRquest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
try {
//recupertaion de l'action
String action = request.getParameter("action");
//execution du traitement
if (action.equals("init")){
doInit(request, response);
}else if (action.equals("filmsDuGenre")){
doFilmsDuGenre(request, response);
}else if (action.equals("choix")){
doFilmsSelectionnes(request, response);
}
}catch (Exception ex){
ex.printStackTrace();
}
}
private void doInit(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//creation du DAO si necessaire
CinemaDAO dao = CinemaDAO.getInstance();
//interrogation du modele afin de trouver l'ensemble des genres
List<GenreDTO> ensGenres = dao.findAllGenres();
//sauvegarde de cet ensemmble dans le scop request
request.setAttribute("ensGenres", ensGenres);
System.out.println(ensGenres);
//alternative pour sauvegarder l'ens des genres de session
//request.getSession().setAttribute("ensGenres", ensGenres);
//prochaine vue
String url = "pages/afficheGenre.jsp";
forward(url, request, response);
}
private void doFilmsDuGenre(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//recuperation du numero du film du genre choisi
String choix = request.getParameter("genre");
int ngenre = Integer.parseInt(choix);
//interrogation du model afin de recuperer les film de cet acteur ainsi que l'acteur
CinemaDAO dao = CinemaDAO.getInstance();
List<FilmDTO> ensFilms = dao.findFilmsOfGenre(ngenre);
GenreDTO genre = dao.findGenreById(ngenre);
//sauvegarde dans le scope request
request.setAttribute("genre", genre);
request.setAttribute("ensFilms", ensFilms);
System.out.println(ensFilms);
//cinematique
String url = "pages/afficheFilmsDuGenre.jsp";
forward(url, request, response);
}
private void doFilmsSelectionnes(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
//recuperation
String[] choix = request.getParameterValues("choix");
//creation du panier
CinemaDAO dao = CinemaDAO.getInstance();
HttpSession session = request.getSession();
Map<String, FilmDTO> ensChoisis = (HashMap<String, FilmDTO>)session.getAttribute("ensChoix");
if(ensChoisis == null){
ensChoisis = new HashMap<>();
}
for (String cle : choix){
int nfilm=Integer.parseInt(cle);
FilmDTO film = dao.findFilmById(nfilm);
ensChoisis.put(cle, film);
}
//sauvegarde
synchronized (session){
session.setAttribute("ensChoix", ensChoisis);
}
//cinematique vers la vue
String url = "pages/afficheFilmsChoisis.jsp";
forward(url, request, response);
}
}
This diff is collapsed.
package dto;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
public class ConnectCinema {
//url de connection
private final static String URL = "jdbc:mysql://localhost:3306/cinema";
//utilisatuer de connection
private final static String USER = "michael";
//mot de passe de connection
private final static String PW = "mdppopmichael";
//SINGLETON
private static Connection INSTANCE;
//constructeur privé
private ConnectCinema() {
try{
INSTANCE = DriverManager.getConnection(URL,USER,PW);
}catch(SQLException e){
e.printStackTrace();
}
}
public static Connection getInstance(){
if (INSTANCE == null){
new ConnectCinema();
}
return INSTANCE;
}
public static void main(String[] args) {
ConnectCinema.getInstance();
}
}
package dto;
import java.io.Serializable;
public class FilmDTO implements Serializable {
// ---------------------attributs d'instance-------------------------
private static final long serialVersionUID = 1L;
private int nfilm ;
private String titre;
private String nomRealisateur;
private String nomActeur;
// ---------------------------- G E T T E R --------------------------
public int getNfilm() {
return nfilm;
}
public String getTitre() {
return titre;
}
public String getNomRealisateur() {
return nomRealisateur;
}
public String getNomActeur() {
return nomActeur;
}
// ----------------------- C O N S T R U C T E U R ---------------------------------
public FilmDTO(int nfilm, String titre, String nomRealisateur, String nomActeur) {
super();
this.nfilm = nfilm;
this.titre = titre;
this.nomRealisateur = nomRealisateur;
this.nomActeur = nomActeur;
}
//--------------------------- T O S T R I N G ---------------------------------------
@Override
public String toString() {
return titre;
}
}
package dto;
import java.io.Serializable;
public class GenreDTO implements Serializable {
private static final long serialVersionUID = 1L;
private int ngenre;
private String nature;
//GETTER SETTER
public int getNgenre() {
return ngenre;
}
public void setNgenre(int ngenre) {
this.ngenre = ngenre;
}
public String getNature() {
return nature;
}
public void setNature(String nature) {
this.nature = nature;
}
public GenreDTO(int ngenre, String nature) {
this.ngenre = ngenre;
this.nature = nature;
}
}
<?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: 24/02/2020
Time: 14:35
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=process?action=init"/>
</head>
<body>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:20
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<c:forEach var="film" items="${ensFilms}">
<tr>
<td>${film.titre}</td>
<td>${film.nomRealisateur}</td>
<td>${film.nomActeur}</td>
</tr>
</c:forEach>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 16:17
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
<h1>Films choisi</h1>
<c:forEach var="choix" items="${ensChoix}">
${choix.value.titre}
<br>
</c:forEach>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:24
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Title</title>
</head>
<body>
Fils du genre ${genre.nature}
<br>
<form action="process?action=choix" method="POST">
<table>
<thead>
<tr>
<th>Titre</th>
<th>Réalisateur</th>
<th>Acteur</th>
<th>Choix</th>
</tr>
</thead>
<tbody>
<c:forEach var="film" items="${ensFilms}">
<tr>
<td>${film.titre}</td>
<td>${film.nomRealisateur}</td>
<td>${film.nomActeur}</td>
<td><input type="checkbox" name="choix" value="${film.nfilm}"/></td>
</tr>
</c:forEach>
</tbody>
</table>
<input type="submit" value="votre panier">
</form>
</body>
</html>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 15:14
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Vue choix</title>
</head>
<body>
<form method="POST" action="process?action=filmsDuGenre">
<fieldset>
<legend> choix d'un genre</legend>
Genre:
<select name="genre">
<c:forEach var="genre" items="${ensGenres}">
<option value="${genre.ngenre}">
${genre.nature}
</option>
</c:forEach>
</select>
<input type="submit" value="envoie">
</fieldset>
</form>
</body>
</html>
<?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: 24/02/2020
Time: 11:48
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=process?action=login"/>
</head>
<body>
$END$
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 14:01
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Client connu</title>
</head>
<body>
<h1>Client : ${requestScope.client.nom} ${requestScope.client.prenom}</h1>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 14:19
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="corp">
<section id="formulaire">
<form method="POST" action="process?action=enrClient">
<fieldset id="zone">
<legend>Informations</legend>
<label class="lab" id="lab_alias">Alias : </label>
<input type="text" name="alias" class="input" id="input_alias" placeholder="entrez votre alias" maxlength="70" required>
<br>
<label class="lab" id="lab_nom">Nom : </label>
<input type="text" name="nom" class="input" id="input_nom" placeholder="entrez votre nom" maxlength="70" required>
<br>
<label class="lab" id="lab_prenom">Prenom : </label>
<input type="text" name="prenom" class="input" id="input_prenom" placeholder="votre prénom" maxlength="70" required>
<br>
<label class="lab" id="lab_email">Adresse mail : </label>
<input type="email" name="email" class="input" id="input_mail" placeholder="votre mail" maxlength="70" required>
<br>
<label class="lab" id="lab_pw">Mot de passe : </label>
<input type="password" name="password" class="input" id="input_pw" placeholder="mot de passe" maxlength="30" required>
</fieldset>
<br>
<input type="submit" class="bo_env" id="bp_env" value="Envoyer">
</form>
<p>
</p>
</section>
</div>
</body>
</html>
<%--
Created by IntelliJ IDEA.
User: michael
Date: 24/02/2020
Time: 14:00
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>