Add Session.html and lombok, change property access into field access to lombok.
Tested add Session to user, add method UtilisateurDAO.addToSession Please rerun mvn clean install
This commit is contained in:
18
pom.xml
18
pom.xml
@@ -49,7 +49,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.projectlombok</groupId>
|
<groupId>org.projectlombok</groupId>
|
||||||
<artifactId>lombok</artifactId>
|
<artifactId>lombok</artifactId>
|
||||||
<version>1.18.20</version>
|
<version>1.18.42</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
@@ -70,19 +70,29 @@
|
|||||||
</httpConnector>
|
</httpConnector>
|
||||||
</configuration>
|
</configuration>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-war-plugin</artifactId>
|
||||||
|
<version>3.4.0</version>
|
||||||
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
<version>3.8.1</version>
|
<version>3.11.0</version>
|
||||||
<configuration>
|
<configuration>
|
||||||
<source>1.8</source> <!-- depending on your project -->
|
<source>11</source> <!-- depending on your project -->
|
||||||
<target>1.8</target> <!-- depending on your project -->
|
<target>11</target> <!-- depending on your project -->
|
||||||
<annotationProcessorPaths>
|
<annotationProcessorPaths>
|
||||||
<path>
|
<path>
|
||||||
<groupId>org.mapstruct</groupId>
|
<groupId>org.mapstruct</groupId>
|
||||||
<artifactId>mapstruct-processor</artifactId>
|
<artifactId>mapstruct-processor</artifactId>
|
||||||
<version>${org.mapstruct.version}</version>
|
<version>${org.mapstruct.version}</version>
|
||||||
</path>
|
</path>
|
||||||
|
<path>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.42</version>
|
||||||
|
</path>
|
||||||
<!-- other annotation processors -->
|
<!-- other annotation processors -->
|
||||||
</annotationProcessorPaths>
|
</annotationProcessorPaths>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
|||||||
@@ -14,9 +14,6 @@ public class SessionDAO extends GenericDAOImpl<Integer, Session> {
|
|||||||
this.setClass(Session.class);
|
this.setClass(Session.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public List<Session> findByTheme(String theme){
|
public List<Session> findByTheme(String theme){
|
||||||
EntityTransaction t=em.getTransaction();
|
EntityTransaction t=em.getTransaction();
|
||||||
t.begin();
|
t.begin();
|
||||||
|
|||||||
@@ -2,8 +2,11 @@ package DAO;
|
|||||||
|
|
||||||
import jakarta.persistence.EntityTransaction;
|
import jakarta.persistence.EntityTransaction;
|
||||||
import jakarta.persistence.Query;
|
import jakarta.persistence.Query;
|
||||||
|
import metier.Session;
|
||||||
import metier.Utilisateur;
|
import metier.Utilisateur;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
||||||
public UtilisateurDAO() {
|
public UtilisateurDAO() {
|
||||||
super();
|
super();
|
||||||
@@ -29,4 +32,25 @@ public class UtilisateurDAO extends GenericDAOImpl<Integer, Utilisateur>{
|
|||||||
t.commit();
|
t.commit();
|
||||||
return u;
|
return u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addToSession(int sessionId, int userId) {
|
||||||
|
EntityTransaction t = em.getTransaction();
|
||||||
|
t.begin();
|
||||||
|
Session s = em.find(Session.class, sessionId);
|
||||||
|
Utilisateur u = em.find(Utilisateur.class, userId);
|
||||||
|
|
||||||
|
//ERROR NULLPOINTEREXCEPTION
|
||||||
|
if (u.getSession() == null) {
|
||||||
|
u.setSession(new ArrayList<>());
|
||||||
|
}
|
||||||
|
if (s.getUtilisateurs() == null) {
|
||||||
|
s.setUtilisateurs(new ArrayList<>());
|
||||||
|
}
|
||||||
|
|
||||||
|
//FAUT AJOUTER OWNING SIDE ( Ici u --> s)
|
||||||
|
u.getSession().add(s);
|
||||||
|
s.getUtilisateurs().add(u);
|
||||||
|
em.merge(u);
|
||||||
|
t.commit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,24 +4,18 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
@PrimaryKeyJoinColumn(name = "Choix_Id")
|
||||||
public class Choix extends Reponse{
|
public class Choix extends Reponse{
|
||||||
ArrayList<String> choix;
|
ArrayList<String> choix;
|
||||||
|
|
||||||
public Choix() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getChoix() {
|
|
||||||
return this.choix;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setChoix(ArrayList<String> choix) {
|
|
||||||
this.choix = choix;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String valHTML(){
|
public String valHTML(){
|
||||||
String res = "";
|
String res = "";
|
||||||
|
|||||||
@@ -1,51 +1,27 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
public class Question implements Serializable {
|
public class Question implements Serializable {
|
||||||
private int id;
|
|
||||||
private String question;
|
|
||||||
private Reponse reponse;
|
|
||||||
private Quizz quizz;
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getId() {
|
private int id;
|
||||||
return id;
|
private String question;
|
||||||
}
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToOne(cascade = CascadeType.ALL)
|
@OneToOne(cascade = CascadeType.ALL)
|
||||||
@JoinColumn(name ="bonne_reponse", referencedColumnName = "id")
|
@JoinColumn(name ="bonne_reponse", referencedColumnName = "id")
|
||||||
public Reponse getReponse() {
|
private Reponse reponse;
|
||||||
return reponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReponse(Reponse reponse) {
|
|
||||||
this.reponse = reponse;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="id_quizz")
|
@JoinColumn(name="id_quizz")
|
||||||
public Quizz getQuizz(){
|
private Quizz quizz;
|
||||||
return this.quizz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuizz(Quizz quizz){
|
|
||||||
this.quizz = quizz;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQuestion(){
|
|
||||||
return this.question;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuestion(String question){
|
|
||||||
this.question = question;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,57 +1,30 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
public class Quizz implements Serializable {
|
public class Quizz implements Serializable {
|
||||||
private Session session;
|
|
||||||
private int id;
|
|
||||||
private Utilisateur utilisateur;
|
|
||||||
private List<Question> questions;
|
|
||||||
|
|
||||||
public Quizz(){
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue
|
@GeneratedValue
|
||||||
public int getId(){
|
private int id;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(Integer id){
|
|
||||||
this.id=id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
public Session getSession(){
|
private Session session;
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSession(Session session){
|
|
||||||
this.session=session;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name="id_utilisateur")
|
@JoinColumn(name="id_utilisateur")
|
||||||
public Utilisateur getUtilisateur(){
|
private Utilisateur utilisateur;
|
||||||
return utilisateur;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUtilisateur(Utilisateur u){
|
|
||||||
this.utilisateur=u;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "quizz")
|
@OneToMany(mappedBy = "quizz")
|
||||||
public List<Question> getQuestions(){
|
private List<Question> questions=new ArrayList<Question>();
|
||||||
return this.questions;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setQuestions(List<Question> questions){
|
|
||||||
this.questions = questions;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -4,44 +4,25 @@ import java.io.Serializable;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
@Inheritance(strategy=InheritanceType.JOINED)
|
@Inheritance(strategy=InheritanceType.JOINED)
|
||||||
@DiscriminatorColumn(name="Type_reponse")
|
@DiscriminatorColumn(name="Type_reponse")
|
||||||
@DiscriminatorValue("Reponse")
|
@DiscriminatorValue("Reponse")
|
||||||
public abstract class Reponse implements Serializable {
|
public abstract class Reponse implements Serializable {
|
||||||
private int id;
|
|
||||||
private Question question;
|
|
||||||
public List<String> reponses;
|
|
||||||
|
|
||||||
public Reponse(){}
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.AUTO)
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
public int getId() {
|
private int id;
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToOne
|
@OneToOne
|
||||||
public Question getQuestion(){
|
private Question question;
|
||||||
return this.question;
|
public List<String> reponses;
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuestion(Question question){
|
|
||||||
this.question=question;
|
|
||||||
}
|
|
||||||
|
|
||||||
public List<String> getReponses(){
|
|
||||||
return this.reponses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setReponses(List<String> reponses){
|
|
||||||
this.reponses=reponses;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String valHTML(){
|
public String valHTML(){
|
||||||
return "";
|
return "";
|
||||||
|
|||||||
@@ -2,23 +2,18 @@ package metier;
|
|||||||
|
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.PrimaryKeyJoinColumn;
|
import jakarta.persistence.PrimaryKeyJoinColumn;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
@PrimaryKeyJoinColumn(name = "RC_Id")
|
@PrimaryKeyJoinColumn(name = "RC_Id")
|
||||||
public class ReponseCourte extends Reponse{
|
public class ReponseCourte extends Reponse{
|
||||||
String value;
|
String value;
|
||||||
|
|
||||||
public ReponseCourte(){
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value){
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
public String getValue(){
|
|
||||||
return this.value;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String valHTML(){
|
public String valHTML(){
|
||||||
return "INPUT";
|
return "INPUT";
|
||||||
|
|||||||
@@ -5,54 +5,22 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
public class Session implements Serializable {
|
public class Session implements Serializable {
|
||||||
private int codePIN;
|
|
||||||
private List<Quizz> quizzs;
|
|
||||||
private List<Utilisateur> utilisateurs;
|
|
||||||
private String theme;
|
|
||||||
|
|
||||||
public Session(){
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCodePIN(int codePIN){
|
|
||||||
this.codePIN = codePIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getCodePIN(){
|
private int codePIN;
|
||||||
return this.codePIN;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuizzs(List<Quizz> quizzs){
|
|
||||||
this.quizzs = quizzs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(mappedBy="session")
|
@OneToMany(mappedBy="session")
|
||||||
public List<Quizz> getQuizzs(){
|
private List<Quizz> quizzs = new ArrayList<>();
|
||||||
return this.quizzs;
|
private List<Utilisateur> utilisateurs = new ArrayList<>();
|
||||||
}
|
private String theme;
|
||||||
|
|
||||||
public void setUtilisateurs(List<Utilisateur> utilisateurs){
|
|
||||||
this.utilisateurs = utilisateurs;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany(mappedBy = "session")
|
|
||||||
public List<Utilisateur> getUtilisateurs() {
|
|
||||||
return this.utilisateurs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTheme(){
|
|
||||||
return this.theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setTheme(String theme){
|
|
||||||
this.theme = theme;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addUser(Utilisateur user){
|
|
||||||
this.utilisateurs.add(user);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -1,48 +1,24 @@
|
|||||||
package metier;
|
package metier;
|
||||||
|
|
||||||
import jakarta.persistence.*;
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@NoArgsConstructor
|
||||||
public class Utilisateur implements Serializable {
|
public class Utilisateur implements Serializable {
|
||||||
|
|
||||||
private int id;
|
|
||||||
private String name;
|
|
||||||
private List<Session> session;
|
|
||||||
private String email;
|
|
||||||
private String password;
|
|
||||||
private List<Quizz> quizzs;
|
|
||||||
|
|
||||||
public Utilisateur() {}
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
public int getId() {
|
private int id;
|
||||||
return id;
|
private String name;
|
||||||
}
|
|
||||||
|
|
||||||
public void setId(int id) {
|
|
||||||
this.id = id;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Column(unique=true)
|
@Column(unique=true)
|
||||||
public String getEmail() {
|
private String email;
|
||||||
return email;
|
private String password;
|
||||||
}
|
|
||||||
|
|
||||||
public void setEmail(String email) {
|
|
||||||
this.email = email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@ManyToMany
|
@ManyToMany
|
||||||
@JoinTable(
|
@JoinTable(
|
||||||
@@ -50,28 +26,9 @@ public class Utilisateur implements Serializable {
|
|||||||
joinColumns = @JoinColumn(name="utilisateur_id"),
|
joinColumns = @JoinColumn(name="utilisateur_id"),
|
||||||
inverseJoinColumns = @JoinColumn(name = "session_pin")
|
inverseJoinColumns = @JoinColumn(name = "session_pin")
|
||||||
)
|
)
|
||||||
public List<Session> getSession() {
|
private List<Session> session= new ArrayList<>();;
|
||||||
return session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setSession(List<Session> session){
|
|
||||||
this.session = session;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getPassword() {
|
|
||||||
return this.password;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setPassword(String password) {
|
|
||||||
this.password = password;
|
|
||||||
}
|
|
||||||
|
|
||||||
@OneToMany(mappedBy = "utilisateur")
|
@OneToMany(mappedBy = "utilisateur")
|
||||||
public List<Quizz> getQuizzs() {
|
private List<Quizz> quizzs;
|
||||||
return quizzs;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setQuizzs(List<Quizz> quizzs) {
|
|
||||||
this.quizzs = quizzs;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -10,14 +10,28 @@ import jakarta.servlet.http.HttpServlet;
|
|||||||
import jakarta.servlet.http.HttpServletRequest;
|
import jakarta.servlet.http.HttpServletRequest;
|
||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
import metier.Session;
|
||||||
import metier.Utilisateur;
|
import metier.Utilisateur;
|
||||||
|
|
||||||
@WebServlet(name="session", urlPatterns={"/SessionInfo"})
|
@WebServlet(name = "session", urlPatterns = {"/SessionInfo"})
|
||||||
public class SessionInfo extends HttpServlet {
|
public class SessionInfo extends HttpServlet {
|
||||||
SessionDAO sessionDAO = new SessionDAO();
|
SessionDAO sessionDAO = new SessionDAO();
|
||||||
|
UtilisateurDAO uDAO = new UtilisateurDAO();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
req.getRequestDispatcher("/Session.html").forward(req, resp);
|
req.getRequestDispatcher("/Session.html").forward(req, resp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||||
|
// Créer une nouvelle session
|
||||||
|
String theme = req.getParameter("theme");
|
||||||
|
Session s = new Session();
|
||||||
|
s.setTheme(theme);
|
||||||
|
sessionDAO.create(s);
|
||||||
|
|
||||||
|
resp.getWriter().println("<h1>Session creee avec code PIN: " +
|
||||||
|
s.getCodePIN() + "</h1>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
package servlet;
|
package servlet;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
@@ -10,7 +11,7 @@ import jakarta.servlet.http.HttpServletRequest;
|
|||||||
import jakarta.servlet.http.HttpServletResponse;
|
import jakarta.servlet.http.HttpServletResponse;
|
||||||
import metier.Utilisateur;
|
import metier.Utilisateur;
|
||||||
|
|
||||||
@WebServlet(name="userinfo", urlPatterns={"/UserInfo"})
|
@WebServlet(name = "userinfo", urlPatterns = {"/UserInfo"})
|
||||||
public class UserInfo extends HttpServlet {
|
public class UserInfo extends HttpServlet {
|
||||||
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
|
||||||
|
|
||||||
@@ -21,18 +22,27 @@ public class UserInfo extends HttpServlet {
|
|||||||
|
|
||||||
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||||
response.setContentType("text/html");
|
response.setContentType("text/html");
|
||||||
|
String action = request.getParameter("action");
|
||||||
|
|
||||||
Utilisateur u = new Utilisateur();
|
if ("addUser".equals(action)) {
|
||||||
u.setName(request.getParameter("name"));
|
Utilisateur u = new Utilisateur();
|
||||||
u.setEmail(request.getParameter("email"));
|
u.setName(request.getParameter("name"));
|
||||||
|
u.setEmail(request.getParameter("email"));
|
||||||
|
|
||||||
utilisateurDAO.create(u);
|
utilisateurDAO.create(u);
|
||||||
PrintWriter out = response.getWriter();
|
PrintWriter out = response.getWriter();
|
||||||
out.println("<HTML>\n<BODY>\n" +
|
out.println("<HTML>\n<BODY>\n" +
|
||||||
"<H1>Recapitulatif des informations de Tibo</H1>\n" +
|
"<H1>Recapitulatif des informations de Tibo</H1>\n" +
|
||||||
"<UL>\n" + " <LI>Nom: " + request.getParameter("name") +
|
"<UL>\n" + " <LI>Nom: " + request.getParameter("name") +
|
||||||
"\n" + " <LI>Email: " + request.getParameter("email") + "\n" +
|
"\n" + " <LI>Email: " + request.getParameter("email") + "\n" +
|
||||||
"</BODY></HTML>");
|
"</BODY></HTML>");
|
||||||
|
} else if ("addSession".equals(action)) {
|
||||||
|
int sessionId = Integer.parseInt(request.getParameter("sessionId"));
|
||||||
|
int userId = Integer.parseInt(request.getParameter("userId"));
|
||||||
|
utilisateurDAO.addToSession(sessionId, userId);
|
||||||
|
response.getWriter().println("<h1> Reussi d'ajouter utilisateur " +
|
||||||
|
userId + " au session " + sessionId + "</h1>");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,13 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<form action="QuizzInfo" method="POST">
|
<h1>Creer une session</h1>
|
||||||
<h1>Creer session</h1>
|
<form action="SessionInfo" method="POST">
|
||||||
Theme Session : <INPUT type="text" name="theme" size="20"><BR>
|
<input type="hidden" name="action" value="createSession">
|
||||||
<INPUT type="submit" value="Creer Quizz"></INPUT>
|
Theme: <input type="text" name="theme">
|
||||||
</form>
|
<input type="submit" value="Creer Session">
|
||||||
</body>
|
</form>
|
||||||
|
|
||||||
|
|
||||||
|
</body>
|
||||||
</html>
|
</html>
|
||||||
@@ -1,10 +1,20 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<body>
|
<body>
|
||||||
<FORM Method="POST" Action="/UserInfo">
|
<h1>Creer l'utilisateur</h1>
|
||||||
|
<FORM Method="POST" Action="UserInfo">
|
||||||
|
<input type="hidden" name="action" value="addUser">
|
||||||
Name : <INPUT type="text" size="20" name="name"><BR>
|
Name : <INPUT type="text" size="20" name="name"><BR>
|
||||||
Email : <INPUT type="text" size="20" name="email"><BR>
|
Email : <INPUT type="text" size="20" name="email"><BR>
|
||||||
<INPUT type="submit" value="Send">
|
<INPUT type="submit" value="Send">
|
||||||
</FORM>
|
</FORM>
|
||||||
|
|
||||||
|
<h1>Ajouter utilisateur dans une session</h1>
|
||||||
|
<form action="UserInfo" method="POST">
|
||||||
|
<input type="hidden" name="action" value="addSession">
|
||||||
|
ID Session: <input type="number" name="sessionId"><br>
|
||||||
|
ID Utilisateur: <input type="number" name="userId"><br>
|
||||||
|
<input type="submit" value="Ajouter">
|
||||||
|
</form>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>Hello World!</h1>
|
<h1>Hello World!</h1>
|
||||||
<a href =http://localhost:8080/myform.html>myform</a>
|
<a href =http://localhost:8080/UserInfo.html>myform</a>
|
||||||
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
||||||
|
|
||||||
<a href =Show>show</a>
|
<a href =Show>show</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user