Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
javab_20230617
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
javab_20230617
Commits
8e83395d
Commit
8e83395d
authored
Jul 02, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wersje JSP 3 i 4
parent
8aa6a58e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
96 additions
and
0 deletions
+96
-0
pom.xml
PC24-SklepWeb/pom.xml
+12
-0
products3.jsp
PC24-SklepWeb/src/main/webapp/products3.jsp
+44
-0
products4.jsp
PC24-SklepWeb/src/main/webapp/products4.jsp
+40
-0
No files found.
PC24-SklepWeb/pom.xml
View file @
8e83395d
...
@@ -20,6 +20,18 @@
...
@@ -20,6 +20,18 @@
<scope>
provided
</scope>
<scope>
provided
</scope>
</dependency>
</dependency>
<dependency>
<dependency>
<groupId>
jakarta.servlet.jsp.jstl
</groupId>
<artifactId>
jakarta.servlet.jsp.jstl-api
</artifactId>
<version>
3.0.0
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.glassfish.web
</groupId>
<artifactId>
jakarta.servlet.jsp.jstl
</artifactId>
<version>
3.0.1
</version>
<scope>
provided
</scope>
</dependency>
<dependency>
<groupId>
org.postgresql
</groupId>
<groupId>
org.postgresql
</groupId>
<artifactId>
postgresql
</artifactId>
<artifactId>
postgresql
</artifactId>
<version>
42.6.0
</version>
<version>
42.6.0
</version>
...
...
PC24-SklepWeb/src/main/webapp/products3.jsp
0 → 100644
View file @
8e83395d
<
%@
page
import=
"sklep.model.Product"
%
>
<
%@
page
import=
"java.util.List"
%
>
<
%@
page
import=
"sklep.db.ProductDAO"
%
>
<
%@
page
import=
"sklep.db.DBConnection"
%
>
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Lista produktów 3
</title>
</head>
<body>
<h1>
Lista produktów - wersja 3 JSP
</h1>
<p>
W tej wersji wewnątrz skryptu JSP umieścimy fragmenty Javy, tzw. scriptlets.
To jest pierwsza techniczna możliwość, którą oferował standard JSP.
</p>
<p>
Uwaga - ta wersja nadal jest nieporządna i
<strong>
nie jest
</strong>
wzorem do naśladowania.
Mieszanie kodu HTML z Javą w taki sposób, szczególnie jak zrobiliśmy z pętlą pod koniec, jest w bardzo złym stylu.
</p>
<p>
[
<a
href=
"index.html"
>
powrót do spisu treści
</a>
]
</p>
<
%
--
Poni
ż
ej
skryptlet
,
kt
ó
ry
otwiera
po
łą
czenie
z
baz
ą
danych:
--
%
>
<
%
DBConnection
db =
DBConnection.open();
ProductDAO
dao =
db.productDAO();
%
>
<p>
Pobieranie danych...
</p>
<
%
List
<
Product
>
products = dao.readAll();
%>
<p>
Pobrano
<
%=
products
.
size
()
%
>
produktów.
</p>
<h3>
Wszystkie produkty
</h3>
<ul>
<
%
for
(
Product
product
:
products
)
{
%
>
<li><
%=
product
.
getProductName
()
%
>
za
<
%=
product
.
getPrice
()
%
></li>
<
%
}
%
>
</ul>
<
%
db
.
close
();
%
>
<p>
[
<a
href=
"index.html"
>
powrót do spisu treści
</a>
]
</p>
</body>
</html>
PC24-SklepWeb/src/main/webapp/products4.jsp
0 → 100644
View file @
8e83395d
<
%@
page
language=
"java"
contentType=
"text/html; charset=UTF-8"
pageEncoding=
"UTF-8"
%
>
<
%@
taglib
prefix=
"c"
uri=
"jakarta.tags.core"
%
>
<
%@
taglib
prefix=
"sql"
uri=
"jakarta.tags.sql"
%
>
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"UTF-8"
>
<title>
Lista produktów 4
</title>
<link
rel=
"stylesheet"
type=
"text/css"
href=
"styl.css"
>
</head>
<body>
<h1>
Lista produktów - wersja 4 JSP
</h1>
<p>
W tej wersji korzystamy ze standardowej biblioteki tagów (JSTL), a dokładnie z jej fragmentu obsługującego SQL.
</p>
<p>
Bezpośrednio w JSP wykonamy zapytanie w bazie danych - to też jeszcze nie będzie najładniejszy styl...
</p>
<
%
--
W
tej
wersji
za
pomoc
ą
dedykowanych
tag
ó
w
JSP
zadamy
zapytanie
SQL
.
Ta
wersja
W
OG
Ó
LE
nie
u
ż
ywa
klas
stworzonych
przez
nas
w
projekcie
;
jest
samowystarczalna
.
--
%
>
<
%
--
"
taglibs
"
-
biblioteki
tag
ó
w
,
zaimplementowane
w
Javie
,
a
w
JSP
u
ż
ywa
si
ę
ich
za
pomoc
ą
sk
ł
adni
"
tagowej
"
(
dok
ł
adnie
sk
ł
adni
XML
)
--
%
>
<sql:setDataSource
var=
"baza"
driver=
"org.postgresql.Driver"
url=
"jdbc:postgresql://localhost/sklep"
user=
"kurs"
password=
"abc123"
/>
<sql:query
dataSource=
"${baza}"
scope=
"page"
var=
"result"
>
SELECT * FROM products ORDER BY product_id
</sql:query>
<
%
--
.
product_name
.
price
itp
-
to
s
ą
nazwy
kolumn
w
tabeli
SQL
--
%
>
<c:forEach
var=
"row"
items=
"${result.rows}"
>
<div
class=
"product"
>
<h3>
${row.product_name}
</h3>
<div
class=
"price"
>
${row.price}
</div>
<p>
${row.description}
</p>
</div>
</c:forEach>
</body>
</html>
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