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
7c9ac9f9
Commit
7c9ac9f9
authored
Jul 15, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Edycja produktu - zapis
parent
a7000ab1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
31 additions
and
1 deletions
+31
-1
AddToBasket.java
PC24-SklepWeb/src/main/java/sklep/basket/AddToBasket.java
+1
-1
EditProduct.java
PC24-SklepWeb/src/main/java/sklep/web/EditProduct.java
+30
-0
No files found.
PC24-SklepWeb/src/main/java/sklep/basket/AddToBasket.java
View file @
7c9ac9f9
...
...
@@ -33,7 +33,7 @@ public class AddToBasket extends HttpServlet {
// ignorujemy błędy
}
// Przekierowanie - każemy przeglądarce wejść pod ten adres.
response
.
sendRedirect
(
"products
8
.jsp"
);
response
.
sendRedirect
(
"products
9
.jsp"
);
}
}
PC24-SklepWeb/src/main/java/sklep/web/EditProduct.java
View file @
7c9ac9f9
package
sklep
.
web
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
jakarta.servlet.RequestDispatcher
;
import
jakarta.servlet.ServletException
;
...
...
@@ -55,4 +56,33 @@ public class EditProduct extends HttpServlet {
dispatcher
.
forward
(
request
,
response
);
}
@Override
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
// W tej wersji nie obsługujemy błędów - w razie błędu wyświetli się strona z wyjątkiem
// W przypadku braku ID zostanie utworzony nowy produkt, a w przypadku podania ID (gdy to była edycja istniejącego) - zostanie zastąpiony.
request
.
setCharacterEncoding
(
"UTF-8"
);
String
parametrId
=
request
.
getParameter
(
"productId"
);
Integer
productId
=
(
parametrId
==
null
||
parametrId
.
isEmpty
())
?
null
:
Integer
.
valueOf
(
parametrId
);
String
parametrPrice
=
request
.
getParameter
(
"price"
);
BigDecimal
price
=
new
BigDecimal
(
parametrPrice
);
String
parametrVat
=
request
.
getParameter
(
"vat"
);
BigDecimal
vat
=
(
parametrVat
==
null
||
parametrVat
.
isEmpty
())
?
null
:
new
BigDecimal
(
parametrVat
);
String
name
=
request
.
getParameter
(
"productName"
);
String
description
=
request
.
getParameter
(
"description"
);
Product
product
=
new
Product
(
productId
,
name
,
price
,
vat
,
description
);
try
(
DBConnection
db
=
DBConnection
.
open
())
{
ProductDAO
productDAO
=
db
.
productDAO
();
productDAO
.
save
(
product
);
db
.
commit
();
// Gdy udało się zapisać, to przejdziemy z powrotem do listy.
response
.
sendRedirect
(
"products9.jsp"
);
}
catch
(
DBException
e
)
{
e
.
printStackTrace
();
}
}
}
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