Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
S
servlets
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Oscar Enrique Gonzalez Escurra
servlets
Commits
750a5979
Commit
750a5979
authored
May 10, 2022
by
OscarGonzalez97
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
se agrega clase de Context y se agregan context-params a la configuracion
parent
bb365c60
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
92 additions
and
0 deletions
+92
-0
src/main/java/com/roshka/bootcamp/Context.java
+75
-0
src/main/webapp/WEB-INF/web.xml
+17
-0
No files found.
src/main/java/com/roshka/bootcamp/Context.java
0 → 100644
View file @
750a5979
package
com
.
roshka
.
bootcamp
;
import
jakarta.servlet.ServletConfig
;
import
jakarta.servlet.ServletContext
;
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
(
"/context"
)
public
class
Context
extends
HttpServlet
{
Connection
connection
;
public
void
init
(
ServletConfig
config
)
{
ServletContext
context
=
config
.
getServletContext
();
try
{
Class
.
forName
(
"org.postgresql.Driver"
);
connection
=
DriverManager
.
getConnection
(
context
.
getInitParameter
(
"dbUrl"
),
context
.
getInitParameter
(
"dbUser"
),
context
.
getInitParameter
(
"dbPassword"
));
}
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
(
"<html>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<h1 style=\"color:red;\">Esta es una url distinta</h1>"
);
while
(
rs
.
next
())
{
String
nombre
=
rs
.
getString
(
"nombre"
);
String
apellido
=
rs
.
getString
(
"apellido"
);
int
cantidad
=
rs
.
getInt
(
"Cantidad_factura"
);
out
.
println
(
"<p>NOMBRE = "
+
nombre
+
"</p>"
);
out
.
println
(
"<p>APELLIDO = "
+
apellido
+
"</p>"
);
out
.
println
(
"<p>CANTIDAD FACTURA = "
+
cantidad
+
"</p>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
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
();
}
}
}
src/main/webapp/WEB-INF/web.xml
View file @
750a5979
...
@@ -14,4 +14,21 @@
...
@@ -14,4 +14,21 @@
<url-pattern>
/hola
</url-pattern>
<url-pattern>
/hola
</url-pattern>
</servlet-mapping>
</servlet-mapping>
<!--Conext params-->
<context-param>
<param-name>
dbUrl
</param-name>
<param-value>
jdbc:postgresql://localhost:5432/bootcamp_market
</param-value>
</context-param>
<context-param>
<param-name>
dbUser
</param-name>
<param-value>
postgres
</param-value>
</context-param>
<context-param>
<param-name>
dbPassword
</param-name>
<param-value>
postgres
</param-value>
</context-param>
<!--Conext params-->
</web-app>
</web-app>
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment