Skip to main content

Mini Project: Light and Dark Theme Switcher (Cookie + Interceptor)

Learn Mini Project: Light and Dark Theme Switcher (Cookie + Interceptor) (Theme Support, Spring MVC) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.

Mini Real-Time Project: Light and Dark Theme Switcher (Cookie + Interceptor) Problem Visitors choose a light or dark theme and expect the site to remember it. Spring MVC used to have a ThemeResolver for this; it was removed in Spring 6, so the same feature is built with a cookie and an interceptor. Requirements Read the theme from ?theme=dark and store it in a cookie for 30 days. On later requests read the cookie and fall back to light. Make the theme available to every page as a request attribute. Ignore invalid values so nobody can inject text into a CSS class. Concepts Used theme switching...

More lessons in Theme Support