From e7bb93c8f4cebc4dfdeec5bbb3d6e36f9b80e4a1 Mon Sep 17 00:00:00 2001 From: krasnoperov Date: Mon, 5 Dec 2022 17:51:55 +0300 Subject: [PATCH] Homework done s4w1 --- .gitignore | 2 + .idea/.gitignore | 8 ++ .idea/compiler.xml | 13 ++ .idea/encodings.xml | 7 + .idea/jarRepositories.xml | 20 +++ .idea/misc.xml | 17 +++ .idea/uiDesigner.xml | 124 ++++++++++++++++ pom.xml | 132 ++++++++++++++++++ src/main/java/com/product/app/Product.java | 23 +++ src/main/java/com/product/app/ServletOne.java | 37 +++++ src/main/webapp/WEB-INF/web.xml | 19 +++ src/main/webapp/index.jsp | 5 + 12 files changed, 407 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/compiler.xml create mode 100644 .idea/encodings.xml create mode 100644 .idea/jarRepositories.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/uiDesigner.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/product/app/Product.java create mode 100644 src/main/java/com/product/app/ServletOne.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.jsp diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..744289d --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +# Project exclude paths +/target/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..6375084 --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/encodings.xml b/.idea/encodings.xml new file mode 100644 index 0000000..aa00ffa --- /dev/null +++ b/.idea/encodings.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..712ab9d --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,20 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..aa4c6d0 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,17 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/uiDesigner.xml b/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..e4789dd --- /dev/null +++ b/pom.xml @@ -0,0 +1,132 @@ + + 4.0.0 + org.example + servletproduct + + war + + 1.0-SNAPSHOT + + + servletproduct Maven Webapp + + + UTF-8 + 1.7 + 1.7 + + + + + + + junit + junit + 4.11 + test + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + + org.slf4j + slf4j-api + 1.7.25 + provided + + + + + + + + servletproduct + + + + + + + org.apache.maven.plugins + maven-dependency-plugin + 2.5.1 + + + ${project.build.directory}/lib/ + + false + false + true + + + + copy-dependencies + package + + copy-dependencies + + + + + + + + + + + + + maven-compiler-plugin + 3.7.0 + + 1.8 + 1.8 + + + + maven-deploy-plugin + 2.8.2 + + + maven-surefire-plugin + 2.20.1 + + + maven-war-plugin + 3.2.0 + + + maven-clean-plugin + 3.0.0 + + + maven-install-plugin + 2.5.2 + + + maven-site-plugin + 3.5.1 + + + maven-jar-plugin + 3.0.2 + + + maven-resources-plugin + 3.0.2 + + + maven-assembly-plugin + 3.1.0 + + + + + + diff --git a/src/main/java/com/product/app/Product.java b/src/main/java/com/product/app/Product.java new file mode 100644 index 0000000..1b07063 --- /dev/null +++ b/src/main/java/com/product/app/Product.java @@ -0,0 +1,23 @@ +package com.product.app; + +public class Product { + + int id; + String title; + int cost; + + public Product(int id, String title, int cost) { + this.id = id; + this.title = title; + this.cost = cost; + } + + @Override + public String toString() { + return "Product{" + + "id=" + id + + ", title='" + title + '\'' + + ", cost=" + cost + + '}'; + } +} diff --git a/src/main/java/com/product/app/ServletOne.java b/src/main/java/com/product/app/ServletOne.java new file mode 100644 index 0000000..efe9655 --- /dev/null +++ b/src/main/java/com/product/app/ServletOne.java @@ -0,0 +1,37 @@ +package com.product.app; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + + +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.annotation.WebServlet; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + +@WebServlet(name = "ServletOne", urlPatterns = "/pr") +public class ServletOne extends HttpServlet { + + protected static Logger logger = LoggerFactory.getLogger(ServletOne.class); + @Override + protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + resp.setContentType("text/html"); + resp.getWriter().printf(""); + + for (int i = 0; i < 10; i++) { + resp.getWriter().printf((new Product(i, "name-" + i, 100+i)).toString()); + } + + resp.getWriter().printf(""); + } + + ServletConfig config=null; + + public void init(ServletConfig config){ + this.config=config; + System.out.println("servlet is initialized"); + } +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..360dd7e --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,19 @@ + + + + Archetype Created Web Application + + + ServletOne + com.product.app.ServletOne + + + ServletOne + /pr1 + + + \ No newline at end of file diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..c38169b --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Hello World!

+ +