avancement de Show, liaison entre Quizz et Question
This commit is contained in:
BIN
data/test.lck
BIN
data/test.lck
Binary file not shown.
@@ -22,4 +22,13 @@ public class Choix extends Reponse{
|
||||
this.choix = choix;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
String res = "";
|
||||
|
||||
for (String val : this.choix) {
|
||||
res+=val+"<br/>";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,9 @@ import java.io.Serializable;
|
||||
@Entity
|
||||
public class Question implements Serializable {
|
||||
private int id;
|
||||
private String question;
|
||||
private Reponse reponse;
|
||||
private Quizz quizz;
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||
@@ -28,4 +30,22 @@ public class Question implements Serializable {
|
||||
this.reponse = reponse;
|
||||
}
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name="id_quizz")
|
||||
public Quizz getQuizz(){
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,12 +2,14 @@ package metier;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
@Entity
|
||||
public class Quizz implements Serializable {
|
||||
private Session session;
|
||||
private int id;
|
||||
private Utilisateur utilisateur;
|
||||
private List<Question> questions;
|
||||
|
||||
public Quizz(){
|
||||
super();
|
||||
@@ -41,4 +43,15 @@ public class Quizz implements Serializable {
|
||||
public void setUtilisateur(Utilisateur u){
|
||||
this.utilisateur=u;
|
||||
}
|
||||
}
|
||||
|
||||
@OneToMany(mappedBy = "quizz")
|
||||
public List<Question> getQuestions(){
|
||||
return this.questions;
|
||||
}
|
||||
|
||||
|
||||
public void setQuestions(List<Question> questions){
|
||||
this.questions = questions;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
package metier;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import jakarta.persistence.*;
|
||||
|
||||
@@ -12,7 +12,7 @@ import jakarta.persistence.*;
|
||||
public abstract class Reponse implements Serializable {
|
||||
private int id;
|
||||
private Question question;
|
||||
public ArrayList<String> reponses;
|
||||
public List<String> reponses;
|
||||
|
||||
public Reponse(){}
|
||||
|
||||
@@ -35,11 +35,16 @@ public abstract class Reponse implements Serializable {
|
||||
this.question=question;
|
||||
}
|
||||
|
||||
public ArrayList<String> getReponses(){
|
||||
public List<String> getReponses(){
|
||||
return this.reponses;
|
||||
}
|
||||
|
||||
public void setReponses(ArrayList<String> reponses){
|
||||
public void setReponses(List<String> reponses){
|
||||
this.reponses=reponses;
|
||||
}
|
||||
|
||||
public String valHTML(){
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,4 +18,9 @@ public class ReponseCourte extends Reponse{
|
||||
public String getValue(){
|
||||
return this.value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String valHTML(){
|
||||
return "INPUT";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,13 +4,13 @@ import java.io.IOException;
|
||||
import java.util.List;
|
||||
|
||||
import DAO.*;
|
||||
import metier.*;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
|
||||
import metier.Utilisateur;
|
||||
|
||||
@WebServlet(name="Show", urlPatterns={"/Show"})
|
||||
public class Show extends HttpServlet {
|
||||
@@ -22,20 +22,56 @@ public class Show extends HttpServlet {
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
||||
response.setContentType("text/html");
|
||||
|
||||
List<Utilisateur> listUser = utilisateurDAO.findAll();
|
||||
String result = "<!DOCTYPE html>"+
|
||||
"<html>"+
|
||||
"<head>"+
|
||||
"<link rel=\"stylesheet\" type=\"text/css\" href=\""+request.getContextPath()+"/css/style.css\">"+
|
||||
"</head>"+
|
||||
"<body>";
|
||||
|
||||
String result = "<HTML>\n<BODY>\n";
|
||||
|
||||
|
||||
//UTILISATEUR
|
||||
List<Utilisateur> listUser = utilisateurDAO.findAll();
|
||||
|
||||
result += "<H2>Utilisateurs :</H2>";
|
||||
result +=
|
||||
"<table class=\"show\">"+
|
||||
"<thead class=\"show\">"+
|
||||
"<tr>"+
|
||||
"<th class=\"show\">ID</th><th class=\"show\">Nom</th><th class=\"show\">mail</th>"+
|
||||
"</tr>"+
|
||||
"</thead>"+
|
||||
"<tbody>";
|
||||
for (Utilisateur u : listUser) {
|
||||
|
||||
result += u.getName();
|
||||
result += u.getId();
|
||||
result += u.getEmail();
|
||||
result += u.getPassword();
|
||||
result+=
|
||||
"<tr>"+
|
||||
"<th class=\"show\">"+u.getId()+"</th>"+"<th class=\"show\">"+u.getName()+"</th>"+"<th class=\"show\">"+u.getEmail()+"</th>"+
|
||||
"</tr>";
|
||||
}
|
||||
result +=
|
||||
"</tbody>"+
|
||||
"</table>";
|
||||
result += "</body>\n</html>";
|
||||
|
||||
result += "</BODY>\n</HTML>";
|
||||
//QUIZZ
|
||||
List<Quizz> listQuizz = quizzDAI.findAll();
|
||||
|
||||
result += "<H2>Quizz :</H2>";
|
||||
for (Quizz quizz : listQuizz) {
|
||||
result += "quizz n°" + quizz.getId() + "<br/>";
|
||||
for (Question question : quizz.getQuestions()) {
|
||||
result += question.getQuestion() + "<br/>";
|
||||
|
||||
result += "choix de réponse : <br/>";
|
||||
result += question.getReponse().valHTML();
|
||||
|
||||
result+= "Reponses corrects :<br/>";
|
||||
for (String reponse : question.getReponse().getReponses()) {
|
||||
result += reponse;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
response.getWriter().write(result);
|
||||
|
||||
|
||||
20
src/main/webapp/css/style.css
Normal file
20
src/main/webapp/css/style.css
Normal file
@@ -0,0 +1,20 @@
|
||||
body{
|
||||
|
||||
}
|
||||
|
||||
table.show{
|
||||
border-collapse: collapse;
|
||||
text-align: left;
|
||||
border: 2px solid #C0C0C0;
|
||||
|
||||
}
|
||||
|
||||
thead.show{
|
||||
background-color: #F0F0F0;
|
||||
}
|
||||
|
||||
th.show{
|
||||
padding-left: 5px;
|
||||
padding-right: 5px;
|
||||
border: 1px solid #C0C0C0
|
||||
}
|
||||
@@ -7,6 +7,8 @@
|
||||
<body>
|
||||
<h1>Hello World!</h1>
|
||||
<a href =http://localhost:8080/myform.html>myform</a>
|
||||
<a href =http://localhost:8080/Quizz.html>Quizz</a>
|
||||
|
||||
<a href =Show>show</a>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user