From 4b6510d23041d390d8503e6c91055c5d9b1a79f5 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Tue, 9 Apr 2019 12:46:21 +0200 Subject: [PATCH] ~ changed helloWorld to find absolute path to config files Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/config/Configuration.java | 9 ++++++--- src/main/java/de/hsel/itech/db/Database.java | 2 +- src/main/java/de/hsel/itech/servlet/HelloWorld.java | 6 +++++- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hsel/itech/config/Configuration.java b/src/main/java/de/hsel/itech/config/Configuration.java index 2f6f02e..3c2b440 100644 --- a/src/main/java/de/hsel/itech/config/Configuration.java +++ b/src/main/java/de/hsel/itech/config/Configuration.java @@ -15,20 +15,23 @@ import java.io.FileReader; * @since 0.1 */ -@Getter @ToString @EqualsAndHashCode public class Configuration { + private static final String filename = "config.json"; + + @Getter private Database database; - public static Configuration get(String fileName) { + + public static Configuration get() { Gson gson = new Gson(); FileReader reader = null; try { - reader = new FileReader(new File(fileName)); + reader = new FileReader(new File(filename)); } catch (FileNotFoundException e) { e.printStackTrace(); } diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 175c1a0..f624cb6 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -20,7 +20,7 @@ public class Database { @Nullable private Connection getConnection() { - Configuration config = Configuration.get("config.json"); + Configuration config = Configuration.get(); try { return DriverManager.getConnection("jdbc:mariadb://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase(), config.getDatabase().getUsername(), config.getDatabase().getPassword()); diff --git a/src/main/java/de/hsel/itech/servlet/HelloWorld.java b/src/main/java/de/hsel/itech/servlet/HelloWorld.java index b22757d..9aa5a44 100644 --- a/src/main/java/de/hsel/itech/servlet/HelloWorld.java +++ b/src/main/java/de/hsel/itech/servlet/HelloWorld.java @@ -3,6 +3,7 @@ package de.hsel.itech.servlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import java.io.File; import java.io.IOException; import java.io.PrintWriter; @@ -30,12 +31,15 @@ public class HelloWorld extends HttpServlet { resp.setContentType("text/html"); final PrintWriter out = resp.getWriter(); + out.println(""); out.println(""); out.println(""); out.println("Hallo Welt!"); out.println(""); out.println(""); - out.println("

Hallo Ostfriesland!

"); + out.println("

Hallo Ostfriesland!


"); + out.println("

" + System.getProperty("catalina.base") + "


"); + out.println("

" + new File("").getAbsolutePath() + "

"); out.println(""); out.println(""); }