From 410004c5577e7a951bbc378e835c4132a263f168 Mon Sep 17 00:00:00 2001 From: joethei Date: Thu, 2 May 2019 16:59:45 +0200 Subject: [PATCH 1/2] Aufgabe 3: fertig --- src/main/java/de/hsel/itech/db/Database.java | 16 ++-- src/main/webapp/categories.jsp | 30 ++++++++ src/main/webapp/category.jsp | 60 +++++++++++++++ src/main/webapp/footer.html | 81 ++++++++++++++++++++ src/main/webapp/header.html | 65 ++++++++++++++++ 5 files changed, 245 insertions(+), 7 deletions(-) create mode 100644 src/main/webapp/categories.jsp create mode 100644 src/main/webapp/category.jsp create mode 100644 src/main/webapp/footer.html create mode 100644 src/main/webapp/header.html diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 1cf745f..42033e2 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -153,15 +153,17 @@ public class Database { @Nullable public Category getCategory(long id) { Map.Entry entry = getResultSetById(category, id); - assert entry != null; - ResultSet rs = entry.getKey(); + if(entry != null) { + ResultSet rs = entry.getKey(); - try { - rs.beforeFirst(); - } catch (SQLException e) { - e.printStackTrace(); + try { + rs.beforeFirst(); + } catch (SQLException e) { + e.printStackTrace(); + } + return getCategory(entry); } - return getCategory(entry); + return null; } /** diff --git a/src/main/webapp/categories.jsp b/src/main/webapp/categories.jsp new file mode 100644 index 0000000..fb879ff --- /dev/null +++ b/src/main/webapp/categories.jsp @@ -0,0 +1,30 @@ +<%@ page import="de.hsel.itech.db.Database" %> +<%@ page import="de.hsel.itech.db.pojo.Category" %> +<%@ page import="java.nio.charset.StandardCharsets" %> +<%@ page import="java.util.Objects" %> +<%@ page contentType="text/html;charset=UTF-8" %> +<%@include file="header.html"%> +<% + request.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); +%> +
+

Kategorien

+
+<% + for(Category category : Objects.requireNonNull(Database.getInstance().getCategories())) { + %> + + <% + } +%> +
+
+<%@include file="footer.html"%> diff --git a/src/main/webapp/category.jsp b/src/main/webapp/category.jsp new file mode 100644 index 0000000..97dbd65 --- /dev/null +++ b/src/main/webapp/category.jsp @@ -0,0 +1,60 @@ +<%@ page import="de.hsel.itech.db.Database" %> +<%@ page import="de.hsel.itech.db.pojo.Book" %> +<%@ page import="de.hsel.itech.db.pojo.Category" %> +<%@ page import="java.util.Objects" %> +<%@ page import="java.nio.charset.StandardCharsets" %> +<%@ page contentType="text/html;charset=UTF-8" %> +<%@include file="header.html" %> +<% + request.setCharacterEncoding(StandardCharsets.UTF_8.name()); + response.setCharacterEncoding(StandardCharsets.UTF_8.name()); + String idValue = request.getParameter("id"); + Category category; + Database db = Database.getInstance(); + if (idValue == null) { +%> +
+ +
+<% +} else { + long id = Long.valueOf(idValue); + category = db.getCategory(id); + if (category != null) { +%> +
+

<%= category.getName() %> +

+
+ <% + for (Book book : Objects.requireNonNull(db.getBooks(category))) { + %> +
+
+ <%=book.getTitle()%> +
<%=book.getTitle()%> +
+
+
+ <% + } + %> +
+
+<% +} else { +%> +
+ +
+<% + } + } +%> + + +<%@include file="footer.html" %> diff --git a/src/main/webapp/footer.html b/src/main/webapp/footer.html new file mode 100644 index 0000000..79088c3 --- /dev/null +++ b/src/main/webapp/footer.html @@ -0,0 +1,81 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/webapp/header.html b/src/main/webapp/header.html new file mode 100644 index 0000000..16fec06 --- /dev/null +++ b/src/main/webapp/header.html @@ -0,0 +1,65 @@ + + + + Amazon light + + + + + + + + + + + + + + + +
+ +
\ No newline at end of file From 93ab2f30392cf35bdb09d72211156347820e93fe Mon Sep 17 00:00:00 2001 From: joethei Date: Fri, 3 May 2019 09:32:39 +0200 Subject: [PATCH 2/2] Aufgabe 3: kleinere fixes --- src/main/webapp/category.jsp | 3 ++- src/main/webapp/index.html | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/webapp/category.jsp b/src/main/webapp/category.jsp index 97dbd65..3bbe69a 100644 --- a/src/main/webapp/category.jsp +++ b/src/main/webapp/category.jsp @@ -10,7 +10,7 @@ response.setCharacterEncoding(StandardCharsets.UTF_8.name()); String idValue = request.getParameter("id"); Category category; - Database db = Database.getInstance(); + if (idValue == null) { %>
@@ -21,6 +21,7 @@ <% } else { long id = Long.valueOf(idValue); + Database db = Database.getInstance(); category = db.getCategory(id); if (category != null) { %> diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index ef273a3..8b1863a 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -7,6 +7,7 @@ \ No newline at end of file