From bb365c603c81633e5d6d1271ed3a6d25d5f32f99 Mon Sep 17 00:00:00 2001 From: OscarGonzalez97 Date: Mon, 9 May 2022 12:33:21 -0400 Subject: [PATCH] se agrega servlet de base de datos --- .idea/.gitignore | 4 ++++ .idea/compiler.xml | 13 +++++++++++++ .idea/encodings.xml | 7 +++++++ .idea/jarRepositories.xml | 20 ++++++++++++++++++++ .idea/misc.xml | 12 ++++++++++++ .idea/vcs.xml | 6 ++++++ pom.xml | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/roshka/bootcamp/BD.java | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/main/java/com/roshka/bootcamp/HelloWorldServlet.java | 22 ++++++++++++++++++++++ src/main/java/com/roshka/bootcamp/Parameter.java | 46 ++++++++++++++++++++++++++++++++++++++++++++++ src/main/webapp/WEB-INF/web.xml | 17 +++++++++++++++++ src/main/webapp/index.jsp | 5 +++++ src/main/webapp/parameters.html | 15 +++++++++++++++ target/classes/com/roshka/bootcamp/BD.class | Bin 0 -> 3512 bytes target/classes/com/roshka/bootcamp/HelloWorldServlet.class | Bin 0 -> 1120 bytes target/classes/com/roshka/bootcamp/Parameter.class | Bin 0 -> 1862 bytes target/maven-archiver/pom.properties | 4 ++++ target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst | 2 ++ target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst | 2 ++ target/servlets/WEB-INF/classes/com/roshka/bootcamp/HelloWorldServlet.class | Bin 0 -> 1103 bytes target/servlets/WEB-INF/classes/com/roshka/bootcamp/Parameter.class | Bin 0 -> 1170 bytes target/servlets/WEB-INF/lib/checker-qual-3.5.0.jar | Bin 0 -> 214381 bytes target/servlets/WEB-INF/web.xml | 16 ++++++++++++++++ target/servlets/index.jsp | 5 +++++ 24 files changed, 354 insertions(+) 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/vcs.xml create mode 100644 pom.xml create mode 100644 src/main/java/com/roshka/bootcamp/BD.java create mode 100644 src/main/java/com/roshka/bootcamp/HelloWorldServlet.java create mode 100644 src/main/java/com/roshka/bootcamp/Parameter.java create mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.jsp create mode 100644 src/main/webapp/parameters.html create mode 100644 target/classes/com/roshka/bootcamp/BD.class create mode 100644 target/classes/com/roshka/bootcamp/HelloWorldServlet.class create mode 100644 target/classes/com/roshka/bootcamp/Parameter.class create mode 100644 target/maven-archiver/pom.properties create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst create mode 100644 target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst create mode 100644 target/servlets/WEB-INF/classes/com/roshka/bootcamp/HelloWorldServlet.class create mode 100644 target/servlets/WEB-INF/classes/com/roshka/bootcamp/Parameter.class create mode 100644 target/servlets/WEB-INF/lib/checker-qual-3.5.0.jar create mode 100644 target/servlets/WEB-INF/web.xml create mode 100644 target/servlets/index.jsp diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..54509b3 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,4 @@ +# Default ignored files +/shelf/ +/workspace.xml +/target \ No newline at end of file diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..b1d1813 --- /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..e022799 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,12 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..03013a1 --- /dev/null +++ b/pom.xml @@ -0,0 +1,88 @@ + + + + 4.0.0 + + com.roshka.bootcamp + servlets + 1.0-SNAPSHOT + war + + servlets Maven Webapp + + http://www.example.com + + + UTF-8 + 1.7 + 1.7 + + + + + junit + junit + 4.11 + test + + + + + + + + + + + org.postgresql + postgresql + 42.3.5 + + + + jakarta.servlet + jakarta.servlet-api + 5.0.0 + provided + + + + + + servlets + + + + maven-clean-plugin + 3.1.0 + + + + maven-resources-plugin + 3.0.2 + + + maven-compiler-plugin + 3.8.0 + + + maven-surefire-plugin + 2.22.1 + + + maven-war-plugin + 3.2.2 + + + maven-install-plugin + 2.5.2 + + + maven-deploy-plugin + 2.8.2 + + + + + diff --git a/src/main/java/com/roshka/bootcamp/BD.java b/src/main/java/com/roshka/bootcamp/BD.java new file mode 100644 index 0000000..10b1cf1 --- /dev/null +++ b/src/main/java/com/roshka/bootcamp/BD.java @@ -0,0 +1,70 @@ +package com.roshka.bootcamp; + +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.PrintWriter; +import java.sql.*; + +@WebServlet("/conexion") +public class BD extends HttpServlet { + Connection connection; + public void init() { + try { + Class.forName("org.postgresql.Driver"); + connection = DriverManager + .getConnection("jdbc:postgresql://localhost:5432/bootcamp_market", + "postgres", "postgres"); + } catch (Exception e) { + e.printStackTrace(); + System.err.println(e.getClass().getName()+": "+e.getMessage()); + System.exit(0); + } + } + + @Override + public void doGet(HttpServletRequest req, HttpServletResponse res) { + try { + Statement stmt = connection.createStatement(); + res.setContentType("text/html"); + PrintWriter out = res.getWriter(); + ResultSet rs = stmt + .executeQuery("select a.nombre, apellido, count(b.cliente_id) Cantidad_factura from cliente a " + + "inner join factura b " + + "on a.id=b.cliente_id " + + "group by a.nombre, a.apellido " + + "order by Cantidad_factura desc;"); + out.println(""); + out.println(""); + while (rs.next()) { + String nombre = rs.getString("nombre"); + String apellido = rs.getString("apellido"); + int cantidad = rs.getInt("Cantidad_factura"); + + out.println("

NOMBRE = \\" + nombre + "

"); + out.println("

APELLIDO = \\" + apellido + "

"); + out.println("

CANTIDAD FACTURA = \\" + cantidad + "

"); + + } + out.println(""); + out.println(""); + rs.close(); + stmt.close(); + } catch (Exception e) { + System.err.println(e.getClass().getName() + ": " + e.getMessage()); + } + + } + + + public void destroy() { + try { + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + } + +} diff --git a/src/main/java/com/roshka/bootcamp/HelloWorldServlet.java b/src/main/java/com/roshka/bootcamp/HelloWorldServlet.java new file mode 100644 index 0000000..09d1a1e --- /dev/null +++ b/src/main/java/com/roshka/bootcamp/HelloWorldServlet.java @@ -0,0 +1,22 @@ +package com.roshka.bootcamp; + +import java.io.IOException; +import java.io.PrintWriter; + + +import jakarta.servlet.*; + +public class HelloWorldServlet extends GenericServlet { + private static final long serialVersionUID = 1L; + + @Override + public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { + response.setContentType("text/html"); + PrintWriter out = response.getWriter(); + out.println(""); + out.println(""); + out.println("

Hola Bootcamp!

"); + out.println(""); + out.println(""); + } +} \ No newline at end of file diff --git a/src/main/java/com/roshka/bootcamp/Parameter.java b/src/main/java/com/roshka/bootcamp/Parameter.java new file mode 100644 index 0000000..239e4c3 --- /dev/null +++ b/src/main/java/com/roshka/bootcamp/Parameter.java @@ -0,0 +1,46 @@ +package com.roshka.bootcamp; +import jakarta.servlet.ServletException; +import jakarta.servlet.annotation.WebServlet; +import jakarta.servlet.http.HttpServlet; +import jakarta.servlet.http.HttpServletRequest; +import jakarta.servlet.http.HttpServletResponse; + +import java.io.IOException; +import java.io.PrintWriter; + +@WebServlet("/parameter") +public class Parameter extends HttpServlet { + + @Override + public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + handleRequest(request, response); + } + + @Override + public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + handleRequest(request, response); + } + + + public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { + + PrintWriter out = response.getWriter(); + response.setContentType("text/plain"); + + String paramName = "nombre"; + String paramValue = request.getParameter(paramName); + + out.write(paramName); + out.write(" = "); + out.write(paramValue); + out.write("n"); + + if (paramValue==null) { + out.write("Parameter " + paramName + " not found"); + } + + out.close(); + + } + +} diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000..9b00007 --- /dev/null +++ b/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,17 @@ + + + + Archetype Created Web Application + + HelloWorldServlet + com.roshka.bootcamp.HelloWorldServlet + + + + HelloWorldServlet + /hola + + + diff --git a/src/main/webapp/index.jsp b/src/main/webapp/index.jsp new file mode 100644 index 0000000..b91b855 --- /dev/null +++ b/src/main/webapp/index.jsp @@ -0,0 +1,5 @@ + + +

Anda a alguna URL

+ + diff --git a/src/main/webapp/parameters.html b/src/main/webapp/parameters.html new file mode 100644 index 0000000..fac149b --- /dev/null +++ b/src/main/webapp/parameters.html @@ -0,0 +1,15 @@ + + + + + Parametros + + + +
+ +
+ +
+ + \ No newline at end of file diff --git a/target/classes/com/roshka/bootcamp/BD.class b/target/classes/com/roshka/bootcamp/BD.class new file mode 100644 index 0000000..fd73819 Binary files /dev/null and b/target/classes/com/roshka/bootcamp/BD.class differ diff --git a/target/classes/com/roshka/bootcamp/HelloWorldServlet.class b/target/classes/com/roshka/bootcamp/HelloWorldServlet.class new file mode 100644 index 0000000..b84676f Binary files /dev/null and b/target/classes/com/roshka/bootcamp/HelloWorldServlet.class differ diff --git a/target/classes/com/roshka/bootcamp/Parameter.class b/target/classes/com/roshka/bootcamp/Parameter.class new file mode 100644 index 0000000..5cde941 Binary files /dev/null and b/target/classes/com/roshka/bootcamp/Parameter.class differ diff --git a/target/maven-archiver/pom.properties b/target/maven-archiver/pom.properties new file mode 100644 index 0000000..58afb6b --- /dev/null +++ b/target/maven-archiver/pom.properties @@ -0,0 +1,4 @@ +#Created by Apache Maven 3.6.3 +groupId=com.roshka.bootcamp +artifactId=servlets +version=1.0-SNAPSHOT diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst new file mode 100644 index 0000000..5ba01d3 --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst @@ -0,0 +1,2 @@ +com\roshka\bootcamp\Parameter.class +com\roshka\bootcamp\HelloWorldServlet.class diff --git a/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst new file mode 100644 index 0000000..35590ab --- /dev/null +++ b/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst @@ -0,0 +1,2 @@ +c:\Users\oscar\Documents\programacion\programacion\java\servlets\src\main\java\com\roshka\bootcamp\Parameter.java +c:\Users\oscar\Documents\programacion\programacion\java\servlets\src\main\java\com\roshka\bootcamp\HelloWorldServlet.java diff --git a/target/servlets/WEB-INF/classes/com/roshka/bootcamp/HelloWorldServlet.class b/target/servlets/WEB-INF/classes/com/roshka/bootcamp/HelloWorldServlet.class new file mode 100644 index 0000000..96d75eb Binary files /dev/null and b/target/servlets/WEB-INF/classes/com/roshka/bootcamp/HelloWorldServlet.class differ diff --git a/target/servlets/WEB-INF/classes/com/roshka/bootcamp/Parameter.class b/target/servlets/WEB-INF/classes/com/roshka/bootcamp/Parameter.class new file mode 100644 index 0000000..f02aed1 Binary files /dev/null and b/target/servlets/WEB-INF/classes/com/roshka/bootcamp/Parameter.class differ diff --git a/target/servlets/WEB-INF/lib/checker-qual-3.5.0.jar b/target/servlets/WEB-INF/lib/checker-qual-3.5.0.jar new file mode 100644 index 0000000..f98cde8 Binary files /dev/null and b/target/servlets/WEB-INF/lib/checker-qual-3.5.0.jar differ diff --git a/target/servlets/WEB-INF/web.xml b/target/servlets/WEB-INF/web.xml new file mode 100644 index 0000000..44cfa4a --- /dev/null +++ b/target/servlets/WEB-INF/web.xml @@ -0,0 +1,16 @@ + + + + Archetype Created Web Application + + HelloWorldServlet + com.roshka.bootcamp.HelloWorldServlet + + + + HelloWorldServlet + /hola + + diff --git a/target/servlets/index.jsp b/target/servlets/index.jsp new file mode 100644 index 0000000..f87c9dd --- /dev/null +++ b/target/servlets/index.jsp @@ -0,0 +1,5 @@ + + +

Hello indes!

+ + -- libgit2 0.26.0