show fini, formulaire pour créer une question PT

This commit is contained in:
trochas
2025-09-29 12:48:09 +02:00
parent 5fbc2045f8
commit 211a168bd0
10 changed files with 173 additions and 7 deletions

View File

@@ -1,6 +1,6 @@
package metier;
import java.util.ArrayList;
import java.util.List;
import jakarta.persistence.Entity;
import jakarta.persistence.PrimaryKeyJoinColumn;
@@ -14,7 +14,7 @@ import lombok.Setter;
@NoArgsConstructor
@PrimaryKeyJoinColumn(name = "Choix_Id")
public class Choix extends Reponse{
ArrayList<String> choix;
List<String> choix;
@Override
public String valHTML(){

View File

@@ -27,4 +27,8 @@ public class Quizz implements Serializable {
@OneToMany(mappedBy = "quizz")
private List<Question> questions=new ArrayList<Question>();
public void addQuestion(Question question) {
this.questions.add(question);
}
}

View File

@@ -0,0 +1,71 @@
package servlet;
import java.io.IOException;
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 DAO.*;
import metier.*;
import java.util.List;
import java.util.Arrays;
@WebServlet(name="question",
urlPatterns={"/QuestionInfo"})
public class QuestionInfo extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.getRequestDispatcher("/Question.html").forward(req, resp);
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
QuizzDAO qDAO = new QuizzDAO();
QuestionDAO questionDAO = new QuestionDAO();
String ennonce = req.getParameter("question");
String type = req.getParameter("type");
String choixPossible = req.getParameter("choixPossible");
String reponse = req.getParameter("reponse");
String idQuizz = req.getParameter("idQuizz");
Question question = new Question();
Quizz quizz = qDAO.findById(Integer.parseInt(idQuizz));
if(quizz==null){
resp.getWriter().println("<HTML>\n<BODY>\n" +
"<H1> Quizz non trouvable </H1>" +
"</BODY></HTML>");
return ;
}
quizz.addQuestion(question);
question.setQuestion(ennonce);
List<String> listRep = Arrays.asList(reponse.split("\n"));
if(type.equals("choix")){
Choix choix = new Choix();
question.setReponse(choix);
List<String> listChoix = Arrays.asList(choixPossible.split("\n"));
choix.setChoix(listChoix);
choix.setReponses(listRep);
}
else if (type.equals("courte")){
ReponseCourte reponseCourte = new ReponseCourte();
question.setReponse(reponseCourte);
reponseCourte.setReponses(listRep);
}
else{
resp.getWriter().println("<HTML>\n<BODY>\n" +
"<H1> Type de question non trouvé </H1>" +
"</BODY></HTML>");
return ;
}
questionDAO.create(question);
}
}

View File

@@ -27,10 +27,14 @@ public class SessionInfo extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// Créer une nouvelle session
String theme = req.getParameter("theme");
String codePin = req.getParameter("codePIN");
Session s = new Session();
s.setCodePIN(Integer.parseInt(codePin));
s.setTheme(theme);
sessionDAO.create(s);
resp.getWriter().println("<h1>Session creee avec id: " +
s.getId() + "</h1>");
resp.getWriter().println("<h1>Session creee avec code PIN: " +
s.getCodePIN() + "</h1>");
}

View File

@@ -14,8 +14,8 @@ import jakarta.servlet.http.HttpServletResponse;
@WebServlet(name="Show", urlPatterns={"/Show"})
public class Show extends HttpServlet {
Utilisateur u;
QuizzDAO quizzDAI = new QuizzDAO();
QuizzDAO quizzDAO = new QuizzDAO();
SessionDAO sessionDAO = new SessionDAO();
UtilisateurDAO utilisateurDAO = new UtilisateurDAO();
@Override
@@ -52,14 +52,15 @@ public class Show extends HttpServlet {
result +=
"</tbody>"+
"</table>";
result += "</body>\n</html>";
//QUIZZ
List<Quizz> listQuizz = quizzDAI.findAll();
List<Quizz> listQuizz = quizzDAO.findAll();
result += "<H2>Quizz :</H2>";
for (Quizz quizz : listQuizz) {
result += "quizz n°" + quizz.getId() + "<br/>";
result += "Admin" + quizz.getUtilisateur().getEmail() + " (id: " + quizz.getUtilisateur().getId() + ") <br/>";
result += "nb Question :" + quizz.getQuestions().size() +"<br/>";
for (Question question : quizz.getQuestions()) {
result += question.getQuestion() + "<br/>";
@@ -73,6 +74,45 @@ public class Show extends HttpServlet {
}
}
//SESSION
List<Session> listSession = sessionDAO.findAll();
result += "<H2>Session : </H2>";
result +=
"<table class=\"show\">"+
"<thead class=\"show\">"+
"<tr>"+
"<th class=\"show\">ID</th><th class=\"show\">Theme</th><th class=\"show\">Code PIN</th><th class=\"show\">Qizzs</th><th class=\"show\">Participants</th>"+
"</tr>"+
"</thead>"+
"<tbody>";
for(Session session : listSession){
result+=
"<tr>"+
"<th class=\"show\">"+session.getId()+"</th>"+"<th class=\"show\">"+session.getTheme()+"</th>"+"<th class=\"show\">"+session.getCodePIN()+"</th>";
String quizzsID = "";
for(Quizz quizz : session.getQuizzs()){
quizzsID += quizz.getId() + " ; ";
}
String UtilisateurID = "";
for(Utilisateur utilisateur : session.getUtilisateurs()){
UtilisateurID += utilisateur.getId() + " ; ";
}
result += "<th class=\"show\">"+quizzsID+"</th>"+"<th class=\"show\">"+UtilisateurID+"</th>";
result+="</tr>";
}
result +=
"</tbody>"+
"</table>";
//HTML END
result += "</body>\n</html>";
response.getWriter().write(result);
}
}

View File

@@ -0,0 +1,41 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html lang="fr">
<body>
<h1>Creer une Question</h1>
<form action="QuestionInfo" method="POST">
<input type="hidden" name="action" value="createSession">
Ennoncé de la question : <input type="text" name="question"><br/>
Type :
<select id="type" name="type">
<option value="choix">Choix multiple</option>
<option value="courte">Réponse courte</option>
</select><br/>
<div id="DivChoix">
Choix possible (séparez avec des retour à la ligne):<br/>
<textarea id="choixPossible" name="choixPossible" rows="5" cols="40"></textarea><br/>
</div>
Réponse autorisée (séparez avec des retour à la ligne):<br/>
<textarea id="reponse" name="reponse" rows="5" cols="40"></textarea><br/>
ID Quizz: <input type="number" name="idQuizz"><br/>
<input type="submit" value="Creer Session">
</form>
<script>
const select = document.getElementById('type');
const contenu1 = document.getElementById('DivChoix');
select.addEventListener('change', function () {
if (this.value === 'choix') {
contenu1.style.display = 'block';
} else{
contenu1.style.display = 'none';
}
});
</script>
</body>
</html>

View File

@@ -1,4 +1,5 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html lang="en">
<body>
<form action="QuizzInfo" method="POST">

View File

@@ -1,10 +1,12 @@
<!DOCTYPE html>
<meta charset="UTF-8">
<html lang="en">
<body>
<h1>Creer une session</h1>
<form action="SessionInfo" method="POST">
<input type="hidden" name="action" value="createSession">
Theme: <input type="text" name="theme">
CodePin <input type="number" name="codePIN">
<input type="submit" value="Creer Session">
</form>

View File

@@ -7,7 +7,10 @@
<body>
<h1>Hello World!</h1>
<a href =http://localhost:8080/UserInfo.html>myform</a>
<a href =http://localhost:8080/Session.html>session</a>
<a href =http://localhost:8080/Quizz.html>Quizz</a>
<a href =http://localhost:8080/Question.html>Question</a>
<a href =Show>show</a>
</body>