mirror of
https://github.com/kmitresse/Cards-Rush.git
synced 2026-05-13 17:11:49 +00:00
draft: dev-web - get img
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
package uppa.project.servlet.api.img;
|
||||
|
||||
import jakarta.servlet.annotation.WebServlet;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
import jakarta.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
|
||||
@WebServlet(name = "imgGetterServlet", value = "/api/imgGet")
|
||||
public class ImgGetterServlet extends HttpServlet {
|
||||
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
|
||||
// Récupérer le nom de l'image à partir de la requête
|
||||
String imgName = request.getParameter("imgName");
|
||||
|
||||
// Vérifier si le nom de l'image est fourni
|
||||
if (imgName != null && !imgName.isEmpty()) {
|
||||
// Récupérer le chemin complet de l'image (remplacez "path_to_your_images_folder" par le chemin réel)
|
||||
String imagePath = request.getRequestDispatcher("/img/" + imgName).toString();
|
||||
|
||||
// Ouvrir un flux d'entrée vers le fichier image
|
||||
try (InputStream inputStream = getServletContext().getResourceAsStream(imagePath)) {
|
||||
if (inputStream != null) {
|
||||
// Récupérer le flux de sortie de la réponse HTTP
|
||||
OutputStream outputStream = response.getOutputStream();
|
||||
|
||||
// Lire les données de l'image et écrire dans le flux de sortie de la réponse
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = inputStream.read(buffer)) != -1) {
|
||||
outputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
|
||||
// Flusher le flux de sortie
|
||||
outputStream.flush();
|
||||
} else {
|
||||
// Si l'image n'est pas trouvée, retourner une réponse 404 (non trouvé)
|
||||
response.sendError(HttpServletResponse.SC_NOT_FOUND);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Si le nom de l'image n'est pas fourni, retourner une réponse 400 (mauvaise requête)
|
||||
response.sendError(HttpServletResponse.SC_BAD_REQUEST);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
<style><%@include file="../static/css/navbar.css"%></style>
|
||||
<nav>
|
||||
<a href="index"><img src="${pageContext.request.contextPath}/api/imgGet?imgName=CardRushLogo.png" alt="Logo CardsRush"> </a>
|
||||
<p>
|
||||
username: <!-- Récuperer le nom utilisateur --> <br/>
|
||||
best score: <!-- Récuperer le meilleur score -->
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
<label for="nbValues">Nb valeurs par couleurs</label>
|
||||
<input type="range" id="nbValues" name="nbValues" min="<%= Deck.NB_VALUES_PER_COLOR_MIN %>" max="<%= Deck.NB_VALUES_PER_COLOR_MAX %>" value="<%= Deck.NB_VALUES_PER_COLOR_MAX %>">
|
||||
<label for="nbRounds">Nombre de tours</label>
|
||||
<input type="number" id="nbRounds" name="nbRounds" min="<%= Game.NB_ROUNDS_MIN %>" max="<%= Deck.NB_COLORS_MAX * Deck.NB_VALUES_PER_COLOR_MAX %>" value="Deck.NB_COLORS_MAX * Deck.NB_VALUES_PER_COLOR_MAX">
|
||||
<input type="number" id="nbRounds" name="nbRounds" min="<%= Game.NB_ROUNDS_MIN %>" max="<%= Deck.NB_COLORS_MAX * Deck.NB_VALUES_PER_COLOR_MAX %>" value="<%= Deck.NB_COLORS_MAX * Deck.NB_VALUES_PER_COLOR_MAX %>">
|
||||
</form>
|
||||
</div>
|
||||
<div id="players-selection">
|
||||
|
||||
@@ -15,12 +15,11 @@
|
||||
<div class="main-button">
|
||||
<button class="modal-toggle" data-target="#newGameModal" >Nouvelle Partie</button>
|
||||
<button class="modal-toggle" data-target="#statisticsModal" >Statistiques</button>
|
||||
<%@include file="../components/new-game.jsp"%>
|
||||
<%@include file="../components/statistics.jsp"%>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
</main>
|
||||
<%@include file="../components/new-game.jsp"%>
|
||||
<%@include file="../components/statistics.jsp"%>
|
||||
</body>
|
||||
<script defer type="text/javascript"><%@include file="../static/js/modal.js"%></script>
|
||||
<script defer type="text/javascript"><%@include file="../static/js/new-game.js"%></script>
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 12 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 123 B |
Binary file not shown.
|
After Width: | Height: | Size: 123 B |
Reference in New Issue
Block a user