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..3bbe69a --- /dev/null +++ b/src/main/webapp/category.jsp @@ -0,0 +1,61 @@ +<%@ 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; + + if (idValue == null) { +%> +
+ +
+<% +} else { + long id = Long.valueOf(idValue); + Database db = Database.getInstance(); + 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 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