Spring MVC: Exposing cookies to the view

by Dejan Bosanac

Recently I needed to display some information on the web page
according to the value of a cookie. I think that this is one of the
common web application functionalities that have been around for a
decade.
If you have ever used Spring MVC you know that view resolvers could be
instructed to expose request and session attributes as view variables.
It is done through the
<property name="exposeSessionAttributes"><value>true</value></property>
<property name="exposeRequestAttributes"><value>true</value></property>

properties in the appropriate view resolver configuration.
I wonder why there is no similar functionality for cookies, such as:
<property name="exposeCookies"><value>true</value></property>

or something similar.

Currently you have two options to deal with this issue:

  • Find cookies of interest in the controller and add it to the model manually.
  • Deal with the cookies in the view by using JavaScript.


I know that both of these ways are perfectly valid and will do the
trick for you, but this is one of the fundamental web features (and so
easy to implement) that I wonder how no one asked for it before. I
googled for it and found nothing. Or am I just missing something?

2 Comments

orpha
2006-07-02 05:08:27
This site is a lot of fun very well designed. nokia6630
http://music-lyrics-61723a500.bigcitybucks.info/ music lyrics
2006-10-12 01:56:46
Hi all!


G'night