Exercises Summary Make A Shopping Cart Using Sessions For Storage This Is Easy Stuff Now That You Ve Seen It Done Spen 1 (90.75 KiB) Viewed 33 times
Exercises Summary Make A Shopping Cart Using Sessions For Storage This Is Easy Stuff Now That You Ve Seen It Done Spen 2 (80.64 KiB) Viewed 33 times
Exercises Summary Make a shopping cart using sessions for storage! This is easy stuff now that you've seen it done! Spend some time and make it amazing when it works! Exercises Start with the storage. Create a Phone POJO capable of storing an id, a phone model, and a phone price. Lombok as needed. Create an index.html page where you display list from a session attribute representing any phones you hope to purchase. You know enough now to pull this off on your own! Remember, ${session....) to retrieve attributes from a session! Create a form on index.html bound to a phone (model) attribute. Your users should be able to easily enter info here about what they hope to purchase. Post from your form back to "/insertPhone" and use a ModelAttribute to retrieve your form data in a pre- populated Phone instance. In the "/insertPhone" mapped method, create an empty List<Phone>. Check if your session isNew(). If it is new, initialize the list of phones so we can store future info in it! If the session is not new, get a (the?) list of phones you stored last time (coming up in a sec) out of it. Either way (new session or old), add the current info your user wishes to purchase to the list, then add the list to the session as an attribute again! Finish it off with a blank Phone in the model again so you can add another at your form! Things to watch for: This algorithm needs to line up with itself exactly in many of the same ways Spring does! If you create a varable phoneList, you must initialize a variable called phoneList or get an attribute and set your phonelist var equal to it. Similarly, the attribute name you get for your phonelist must exarthrental
Create an index.html page where you display list from a session attribute representing any phones you hope to purchase. You know enough now to pull this off on your own! Remember, ${session....) to retrieve attributes from a session! Create a form on index.html bound to a phone (model) attribute. Your users should be able to easily enter info here about what they hope to purchase. Post from your form back to "/insertPhone" and use a ModelAttribute to retrieve your form data in a pre- populated Phone instance. In the "/insertPhone" mapped method, create an empty List<Phone>. Check if your session isNew(). If it is new, initialize the list of phones so we can store future info in it! If the session is not new, get a (the?) list of phones you stored last time (coming up in a sec) out of it. Either way (new session or old), add the current info your user wishes to purchase to the list, then add the list to the session as an attribute again! Finish it off with a blank Phone in the model again so you can add another at your form! Things to watch for: This algorithm needs to line up with itself exactly in many of the same ways Spring does! If you create a varable phoneList, you must initialize a variable called phoneList or get an attribute and set your phonelist var equal to it. Similarly, the attribute name you get for your phoneList must exactly equal the attribute name you set for it a moment later if this is to work! When you get it working, add three or four items to your cart and take a screenshot. Hand in your screenshot to SLATE here with your name as the filename. Style, style, style, and hand it in again!
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!