Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20230403
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
20230403
Commits
80be96ed
Commit
80be96ed
authored
Apr 26, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inicjalizacja sesji w listenerze
parent
99f48cf0
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
38 additions
and
4 deletions
+38
-4
BasketConfig.java
...-SklepSpring/src/main/java/sklep/basket/BasketConfig.java
+18
-0
BasketListener.java
...klepSpring/src/main/java/sklep/basket/BasketListener.java
+20
-0
ProductController.java
...ing/src/main/java/sklep/controller/ProductController.java
+0
-4
No files found.
PC30-SklepSpring/src/main/java/sklep/basket/BasketConfig.java
0 → 100644
View file @
80be96ed
package
sklep
.
basket
;
import
org.springframework.context.annotation.Bean
;
import
org.springframework.context.annotation.Configuration
;
import
jakarta.servlet.http.HttpSessionListener
;
@Configuration
public
class
BasketConfig
{
{
System
.
out
.
println
(
"BasketConfig jest tworzony"
);
}
@Bean
HttpSessionListener
createListener
()
{
return
new
BasketListener
();
}
}
PC30-SklepSpring/src/main/java/sklep/basket/BasketListener.java
0 → 100644
View file @
80be96ed
package
sklep
.
basket
;
import
jakarta.servlet.http.HttpSession
;
import
jakarta.servlet.http.HttpSessionEvent
;
import
jakarta.servlet.http.HttpSessionListener
;
public
class
BasketListener
implements
HttpSessionListener
{
public
void
sessionCreated
(
HttpSessionEvent
se
)
{
HttpSession
session
=
se
.
getSession
();
session
.
setMaxInactiveInterval
(
30
);
// sesja wygasa po pół minuty - tylko na potrzeby zajęć
session
.
setAttribute
(
"basket"
,
new
Basket
());
System
.
out
.
println
(
"Początek sesji "
+
session
.
getId
());
}
public
void
sessionDestroyed
(
HttpSessionEvent
se
)
{
System
.
out
.
println
(
"Koniec sesji "
+
se
.
getSession
().
getId
());
}
}
PC30-SklepSpring/src/main/java/sklep/controller/ProductController.java
View file @
80be96ed
...
...
@@ -109,10 +109,6 @@ public class ProductController {
HttpSession
session
)
{
Basket
basket
=
(
Basket
)
session
.
getAttribute
(
"basket"
);
if
(
basket
==
null
)
{
basket
=
new
Basket
();
session
.
setAttribute
(
"basket"
,
basket
);
}
Optional
<
Product
>
product
=
productRepository
.
findById
(
productId
);
if
(
product
.
isPresent
())
{
basket
.
addProduct
(
product
.
get
());
...
...
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