I need to add a cookie from a filter. I have created a very simple class. Please see attached file. All it does is to cast the ServletResponse object passed to doFilter method and try to add a cookie with HttpServletResponse object. However, I get an exception. Please, could some one help me to add a cookie from a filter?