Move things around
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
package api;
|
||||
package servlet.api;
|
||||
|
||||
import DTO.Order;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -1,4 +1,4 @@
|
||||
package test;
|
||||
package servlet.test;
|
||||
|
||||
import java.io.IOException;
|
||||
import javax.servlet.ServletException;
|
||||
26
src/main/java/util/FileUtil.java
Normal file
26
src/main/java/util/FileUtil.java
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
9
src/main/resources/html/index.html
Normal file
9
src/main/resources/html/index.html
Normal 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>
|
||||
Reference in New Issue
Block a user