Skip to content
Snippets Groups Projects
Commit 4e982958 authored by Gwendal Margely's avatar Gwendal Margely :alembic:
Browse files

Nothing works, and each attempt to fix anything makes things worse, so I'm...

Nothing works, and each attempt to fix anything makes things worse, so I'm gonna stop for tonight, I'll came back after a few hours of sleep when I can be mentally alive back
parent fd1a8aa0
No related branches found
No related tags found
No related merge requests found
Showing
with 119 additions and 10 deletions
File added
File added
File added
File added
File added
File added
File added
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Result</title>
</head>
<body>
<h1>Result</h1>
<p id="result-message"></p>
<script>
document.getElementById("result-message").innerText = "${message}";
</script>
</body>
</html>
......@@ -19,11 +19,11 @@ public class IngredientDAO {
private static ResultSet resultSet;
// SQL queries
private static final String SELECT_ALL_QUERY = "SELECT * FROM ingredients";
private static final String INSERT_QUERY = "INSERT INTO ingredients(nom, price) VALUES (?, ?)";
private static final String SELECT_BY_ID_QUERY = "SELECT nom,price FROM ingredients WHERE id = ?";
private static final String DELETE_QUERY = "DELETE FROM ingredients WHERE id = ?";
private static final String UPDATE_QUERY = "UPDATE ingredients SET nom = ?, price = ? WHERE id = ?";
private static final String SELECT_ALL_QUERY = "SELECT * FROM ingredient";
private static final String INSERT_QUERY = "INSERT INTO ingredient(nom, prix) VALUES (?, ?)";
private static final String SELECT_BY_ID_QUERY = "SELECT nom,prix FROM ingredient WHERE id = ?";
private static final String DELETE_QUERY = "DELETE FROM ingredient WHERE id = ?";
private static final String UPDATE_QUERY = "UPDATE ingredient SET nom = ?, prix = ? WHERE id = ?";
// Method to establish database connection
static Connection connect() throws IngredientDAOException {
......@@ -63,8 +63,8 @@ public class IngredientDAO {
while (resultSet.next()) {
int id = resultSet.getInt("id");
String name = resultSet.getString("nom");
double price = resultSet.getDouble("price");
Ingredient ingredient = new Ingredient(id, name, price);
double prix = resultSet.getDouble("prix");
Ingredient ingredient = new Ingredient(id, name, prix);
ingredients.add(ingredient);
}
} catch (SQLException e) {
......@@ -102,8 +102,8 @@ public class IngredientDAO {
if (resultSet.next()) {
String name = resultSet.getString("nom");
double price = resultSet.getDouble("price");
ingredient = new Ingredient(id, name, price);
double prix = resultSet.getDouble("prix");
ingredient = new Ingredient(id, name, prix);
}
} catch (SQLException e) {
throw new IngredientDAOException("Error fetching ingredient", e);
......
package Servlets;
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 java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
@WebServlet("/database-test")
public class DatabaseTestServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
try {
// Charge le pilote JDBC pour PostgreSQL
Class.forName("org.postgresql.Driver");
// Essaie de se connecter à la base de données
Connection connection = DriverManager.getConnection(
"jdbc:postgresql://localhost:5432/pizzeria", "gwendalmargelyetu", "moi");
// Si la connexion est établie, affiche un message de succès
req.setAttribute("message", "Database test successful.");
} catch (ClassNotFoundException e) {
// Si le pilote JDBC n'est pas trouvé, affiche un message d'erreur
req.setAttribute("message", "Database test failed: JDBC driver not found.");
} catch (SQLException e) {
// Si une exception SQL est levée, affiche un message d'erreur
req.setAttribute("message", "Database test failed: " + e.getMessage());
}
// Renvoie la réponse en utilisant la vue JSP
req.getRequestDispatcher("/WEB-INF/jsp/result.jsp").forward(req, resp);
}
}
......@@ -28,7 +28,7 @@ public class IngredientServlet extends HttpServlet {
}
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
String pathInfo = req.getPathInfo();
if (pathInfo == null || pathInfo.equals("/")) {
// Get all ingredients
......@@ -87,6 +87,7 @@ public class IngredientServlet extends HttpServlet {
}
}
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
// Parse the request body as a JSON object
......@@ -166,3 +167,7 @@ public class IngredientServlet extends HttpServlet {
}
}
}
/*
*/
\ No newline at end of file
File added
<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_3_1.xsd"
version="3.1">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
<jsp-config>
<jsp-property-group>
<url-pattern>*.jsp</url-pattern>
<page-encoding>UTF-8</page-encoding>
</jsp-property-group>
</jsp-config>
<servlet>
<servlet-name>DatabaseTestServlet</servlet-name>
<servlet-class>Servlets.DatabaseTestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DatabaseTestServlet</servlet-name>
<url-pattern>/database-test</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>IngredientServlet</servlet-name>
<servlet-class>Servlets.IngredientServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>IngredientServlet</servlet-name>
<url-pattern>/ingredients/*</url-pattern>
</servlet-mapping>
</web-app>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Test</title>
</head>
<body>
<h1>Test</h1>
<p>This is a test page.</p>
</body>
</html>
......@@ -54,5 +54,7 @@
<build>
<sourceDirectory>WEB-INF/src</sourceDirectory>
<testSourceDirectory>WEB-INF/test</testSourceDirectory>
<outputDirectory>WEB-INF/classes</outputDirectory>
<testOutputDirectory>WEB-INF/test-classes</testOutputDirectory>
</build>
</project>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment