Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HomeWork2 #2

Open
wants to merge 2 commits into
base: HomeWork1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

public interface MedicalCard {
void doShow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

public interface MedicalInstitution {
void visitDoctor();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

public interface Plan {
void doShow();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package homework;
package ru.geekbrains.homework;

public interface Schedule {
void doShow();
Expand Down
95 changes: 95 additions & 0 deletions lesson2/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>base-spring-framework</artifactId>
<groupId>ru.geekbrains</groupId>
<version>1.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>lesson2</artifactId>
<packaging>war</packaging>

<name>lesson2 Maven Webapp</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>4.0.1</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.32</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.22</version>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<finalName>lesson2</finalName>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>2.0.1.Final</version>
</plugin>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- see http://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_war_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
14 changes: 14 additions & 0 deletions lesson2/src/main/java/ru/geekbrains/homework/Product.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ru.geekbrains.homework;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.ToString;

@AllArgsConstructor
@Getter
@ToString
public class Product {
private int id;
private String title;
private double cost;
}
37 changes: 37 additions & 0 deletions lesson2/src/main/java/ru/geekbrains/homework/ProductList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package ru.geekbrains.homework;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.servlet.RequestDispatcher;
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;
import java.util.ArrayList;
import java.util.List;

@WebServlet(name = "ProductList", urlPatterns = "/product_list")
public class ProductList extends HttpServlet {

private static Logger logger = LoggerFactory.getLogger(ProductList.class);

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
logger.info("Method doGet");

List<Product> list = new ArrayList<>();
for (int i = 1; i < 11; i++) {
list.add(new Product(i, "Product" + i, i));
}

req.setAttribute("products", list);

// System.out.println(list);

RequestDispatcher dispatcher = req.getRequestDispatcher("view/product_list.jsp");
dispatcher.forward(req, resp);
}
}
8 changes: 8 additions & 0 deletions lesson2/src/main/webapp/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0">

<display-name>Archetype Created Web Application</display-name>
</web-app>
5 changes: 5 additions & 0 deletions lesson2/src/main/webapp/index.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<html>
<body>
<h2>Hello World!</h2>
</body>
</html>
15 changes: 15 additions & 0 deletions lesson2/src/main/webapp/view/product_list.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<%@ page import="java.util.List" %>
<%@ page import="ru.geekbrains.homework.Product" %>
<html>
<body>
<h2>Product list</h2>
<%
List<Product> list = (List<Product>) request.getAttribute("products");
out.println("<ui>");
for (Product product: list) {
out.println("<li>" + product + "</li>");
}
out.println("</ui>");
%>
</body>
</html>
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<version>1.0-SNAPSHOT</version>
<modules>
<module>lesson1</module>
<module>lesson2</module>
</modules>

<properties>
Expand Down