From ce06c43812aec3801c2b32cf699888be21c93b10 Mon Sep 17 00:00:00 2001 From: Harsha S Jayaram Date: Tue, 5 Jan 2021 17:43:17 +0530 Subject: [PATCH] Java project pull request --- pom.xml | 32 +++++++++++++++++ src/main/java/com/sample/LiquorService.java | 33 +++++++++++++++++ .../java/com/sample/SelectLiquorServlet.java | 36 +++++++++++++++++++ .../java/com/sample/model/LiquorType.java | 9 +++++ src/main/webapp/WEB-INF/web.xml | 3 ++ src/main/webapp/index.html | 27 ++++++++++++++ src/main/webapp/result.jsp | 22 ++++++++++++ 7 files changed, 162 insertions(+) create mode 100644 pom.xml create mode 100644 src/main/java/com/sample/LiquorService.java create mode 100644 src/main/java/com/sample/SelectLiquorServlet.java create mode 100644 src/main/java/com/sample/model/LiquorType.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.html create mode 100644 src/main/webapp/result.jsp diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..98c0d91 --- /dev/null +++ b/pom.xml @@ -0,0 +1,32 @@ + + + 4.0.0 + + com.sample + LiquorStoreApp + 1.0-SNAPSHOT + war + + + + javax.servlet + javax.servlet-api + 3.0.1 + provided + + + + + SampleServlet + + + org.apache.tomcat.maven + tomcat7-maven-plugin + 2.2 + + + + + diff --git a/src/main/java/com/sample/LiquorService.java b/src/main/java/com/sample/LiquorService.java new file mode 100644 index 0000000..5384147 --- /dev/null +++ b/src/main/java/com/sample/LiquorService.java @@ -0,0 +1,33 @@ +package com.sample; + +import com.sample.model.LiquorType; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by kasun on 5/24/17. + */ +public class LiquorService { + + public List getAvailableBrands(LiquorType type){ + + List brands = new ArrayList(); + + if(type.equals(LiquorType.WINE)){ + brands.add("Adrianna Vineyard"); + brands.add(("J. P. Chenet")); + + }else if(type.equals(LiquorType.WHISKY)){ + brands.add("Glenfiddich"); + brands.add("Johnnie Walker"); + + }else if(type.equals(LiquorType.BEER)){ + brands.add("Corona"); + + }else { + brands.add("No Brand Available"); + } + return brands; + } +} diff --git a/src/main/java/com/sample/SelectLiquorServlet.java b/src/main/java/com/sample/SelectLiquorServlet.java new file mode 100644 index 0000000..91f2b77 --- /dev/null +++ b/src/main/java/com/sample/SelectLiquorServlet.java @@ -0,0 +1,36 @@ +package com.sample; + +import com.sample.model.LiquorType; + +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.List; + + +@WebServlet( + name = "selectliquorservlet", + urlPatterns = "/SelectLiquor" +) +public class SelectLiquorServlet extends HttpServlet { + + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { + + String liquorType = req.getParameter("Type"); + + LiquorService liquorService = new LiquorService(); + LiquorType l = LiquorType.valueOf(liquorType); + + List liquorBrands = liquorService.getAvailableBrands(l); + + req.setAttribute("brands", liquorBrands); + RequestDispatcher view = req.getRequestDispatcher("result.jsp"); + view.forward(req, resp); + + } +} diff --git a/src/main/java/com/sample/model/LiquorType.java b/src/main/java/com/sample/model/LiquorType.java new file mode 100644 index 0000000..0886e8d --- /dev/null +++ b/src/main/java/com/sample/model/LiquorType.java @@ -0,0 +1,9 @@ +package com.sample.model; + +/** + * Created by kasun on 5/24/17. + */ +public enum LiquorType { + WINE,BEER,WHISKY + +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..bef8421 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,3 @@ + + COOKIE + \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000..6ce0468 --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,27 @@ + + + + + Welcome to the Store + + +
+

+ Select the type of Drink +

+
+
+ +

+ +
+
+ + + + diff --git a/src/main/webapp/result.jsp b/src/main/webapp/result.jsp new file mode 100644 index 0000000..102228e --- /dev/null +++ b/src/main/webapp/result.jsp @@ -0,0 +1,22 @@ +<%@ page import ="java.util.*" %> + + + +
+

+ Available Brands +

+<% +List result= (List) request.getAttribute("brands"); +Iterator it = result.iterator(); +out.println("
We have

"); + +while(it.hasNext()){ + +out.println(it.next()+"
"); + +} + +%> + + \ No newline at end of file