Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to update a session attribute in Spring MVC web app

I store a shopping cart instance during the checkout process in a session variable via org.springframework.web.bind.annotation.SessionAttributes:

@SessionAttributes({"shoppingCart"})
public class CheckoutController { ... }

However, when the checkout process is completed I want to store a fresh new ShoppingCart instance in the session.

I need something like:

sessionAttributes.set("shoppingCart", new ShoppingCart());

Which method can I use to achieve this task?

like image 973
tschmid Avatar asked Oct 21 '25 04:10

tschmid


1 Answers

If you can access HttpServletRequest, try with this

request.getSession().setAttribute("shoppingCart", new ShoppingCart());
like image 185
Wundwin Born Avatar answered Oct 22 '25 20:10

Wundwin Born