Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_weekendowa_20221008
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
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
java_weekendowa_20221008
Commits
f60d6b18
Commit
f60d6b18
authored
Oct 23, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Serwlety korzystające z DAO
parent
dbbb6c45
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
1 deletions
+92
-1
Products1.java
PC25-SklepWeb/src/main/java/sklep/web/Products1.java
+39
-0
Products2.java
PC25-SklepWeb/src/main/java/sklep/web/Products2.java
+52
-0
styl.css
PC25-SklepWeb/src/main/webapp/styl.css
+1
-1
No files found.
PC25-SklepWeb/src/main/java/sklep/web/Products1.java
0 → 100644
View file @
f60d6b18
package
sklep
.
web
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.List
;
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
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.model.Product
;
@WebServlet
(
"/Products1"
)
public
class
Products1
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/plain"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
List
<
Product
>
products
=
productDAO
.
readAll
();
out
.
println
(
"Odczytano "
+
products
.
size
()
+
" produktów:"
);
for
(
Product
product
:
products
)
{
out
.
println
(
product
);
}
}
catch
(
DBException
e
)
{
e
.
printStackTrace
(
out
);
}
}
}
PC25-SklepWeb/src/main/java/sklep/web/Products2.java
0 → 100644
View file @
f60d6b18
package
sklep
.
web
;
import
java.io.IOException
;
import
java.io.PrintWriter
;
import
java.util.List
;
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
sklep.db.DBConnection
;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.model.Product
;
@WebServlet
(
"/Products2"
)
public
class
Products2
extends
HttpServlet
{
private
static
final
long
serialVersionUID
=
1L
;
protected
void
doGet
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
response
.
setContentType
(
"text/html"
);
response
.
setCharacterEncoding
(
"UTF-8"
);
PrintWriter
out
=
response
.
getWriter
();
out
.
println
(
"<!DOCTYPE html>"
);
out
.
println
(
"<html>"
);
out
.
println
(
"<head>"
);
out
.
println
(
"<title>Lista produktów</title>"
);
out
.
println
(
"<link rel='stylesheet' type='text/css' href='styl.css'>"
);
out
.
println
(
"</head>"
);
out
.
println
(
"<body>"
);
out
.
println
(
"<h1>Lista produktów</h1>"
);
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
List
<
Product
>
products
=
productDAO
.
readAll
();
out
.
printf
(
"<div>Odczytano %d produktów</div>"
,
products
.
size
());
for
(
Product
product
:
products
)
{
out
.
println
(
product
.
toHtml
());
}
}
catch
(
DBException
e
)
{
out
.
println
(
"<pre class='error'>"
);
e
.
printStackTrace
(
out
);
out
.
println
(
"</pre>"
);
}
out
.
println
(
"</body>"
);
out
.
println
(
"</html>"
);
}
}
PC25-SklepWeb/src/main/webapp/styl.css
View file @
f60d6b18
...
...
@@ -5,7 +5,7 @@ body {
/* komentarz w CSS */
h
1
,
h
4
{
h4
{
text-align
:
center
;
}
...
...
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