Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
J
java_dzienna_15_09
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_dzienna_15_09
Commits
54e7a95b
Commit
54e7a95b
authored
Sep 29, 2022
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Zapisywanie zmian w produktach.
parent
678a17bf
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
28 additions
and
1 deletions
+28
-1
EditProduct.java
PC26-SklepWeb/src/main/java/sklep/web/EditProduct.java
+28
-1
No files found.
PC26-SklepWeb/src/main/java/sklep/web/EditProduct.java
View file @
54e7a95b
package
sklep
.
web
;
import
java.io.IOException
;
import
java.math.BigDecimal
;
import
javax.servlet.RequestDispatcher
;
import
javax.servlet.ServletException
;
...
...
@@ -13,6 +14,7 @@ import sklep.db.DBConnection;
import
sklep.db.DBException
;
import
sklep.db.ProductDAO
;
import
sklep.db.RecordNotFound
;
import
sklep.db.SklepException
;
import
sklep.model.Product
;
@WebServlet
(
"/EditProduct"
)
...
...
@@ -46,7 +48,32 @@ public class EditProduct extends HttpServlet {
}
protected
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
doGet
(
request
,
response
);
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
();
}
catch
(
SklepException
e
)
{
e
.
printStackTrace
();
}
request
.
setAttribute
(
"product"
,
product
);
RequestDispatcher
dispatcher
=
request
.
getRequestDispatcher
(
"product_form.jsp"
);
dispatcher
.
forward
(
request
,
response
);
}
}
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