struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "ekoje ekoje" <>
Subject [S2] Filter Cookie
Date Wed, 14 Feb 2007 12:02:40 GMT
Hi Guys,

I would like to check a cookie every time a user try to access my website.
So, I've created an interceptor, it work fine but it didn't work if the user
ask for a JSP page. The interceptor was never called.
So, I've created a filter who check all cookies at every request to my
server. Unfortunetly it doesn't work too, every time my request parameters
and cookies are empty even if I'm sure that I can find a cookie.

Is there anything in Struts 2 who remove all data in the request object ???

Please find the code:
public final class LoginFilter implements Filter {
    private final static String FILTER_APPLIED =

    private FilterConfig filterConfig = null;

    public void init(FilterConfig filterConfig) throws ServletException {
        this.filterConfig = filterConfig;

    public void destroy() {
        this.filterConfig = null;

    public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain)
            throws IOException, ServletException {
        if (request.getAttribute (FILTER_APPLIED) == null) {
            request.setAttribute(FILTER_APPLIED, Boolean.TRUE);
            Cookie[] cookies = ((HttpServletRequest) request).getCookies();

            if (cookies != null) {

                for (int i = 0; i < cookies.length; i++) {
                    if (cookies != null &&
                        System.out.println("cookie found");
                            System.out.println("cookie alive");
                            String[] values =
        chain.doFilter(request, response);

Thanks for your help

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message