Move things around

This commit is contained in:
2018-10-13 19:15:07 +03:00
parent 9c38800214
commit fa0dc0bd2c
6 changed files with 44 additions and 6 deletions

View File

@@ -1,4 +1,4 @@
package api;
package servlet.api;
import DTO.Order;
import com.fasterxml.jackson.databind.ObjectMapper;

View File

@@ -1,4 +1,6 @@
package form;
package servlet.html;
import util.FileUtil;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
@@ -12,6 +14,7 @@ public class Index extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=utf-8");
response.getWriter().print("<a href=/orders/form>Orders form</a>");
String index = FileUtil.readFileFromClasspath("html/index.html");
response.getWriter().print(index);
}
}

View File

@@ -1,7 +1,7 @@
package form;
package servlet.html;
import DTO.Order;
import api.Orders;
import servlet.api.Orders;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;

View File

@@ -1,4 +1,4 @@
package test;
package servlet.test;
import java.io.IOException;
import javax.servlet.ServletException;

View File

@@ -0,0 +1,26 @@
package util;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.stream.Collectors;
public class FileUtil {
public static String readFileFromClasspath(String pathOnClasspath) {
try (InputStream is = FileUtil.class.getClassLoader().getResourceAsStream(pathOnClasspath)) {
if (is == null) {
throw new IllegalStateException("can't load file: " + pathOnClasspath);
}
BufferedReader buffer = new BufferedReader(new InputStreamReader(is));
return buffer.lines().collect(Collectors.joining("\n"));
} catch (IOException e) {
throw new RuntimeException();
}
}
}

View File

@@ -0,0 +1,9 @@
<!doctype html>
<html>
<title>Index</title>
<h1>Shop</h1>
<h3>Menu</h3>
<ul>
<li><a href=/orders/form>Orders form</a></li>
</ul>
</html>