You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Denis Avdic <de...@betterway.net> on 2003/10/18 16:30:21 UTC

[cactus] Cannot set cookies

Hello, 

I've run into a major problem.  

I cannot seem to have cookies run through my web request to my servlet.  

I have this code:

public void beginCactus(WebRequest wr){
        wr.setURL("www.domain.com","", "", null,null);
        wr.addCookie("www.domain.com",ServletUtils.COOKIE_NAME,"glyons");
        wr.addCookie("www.domain.com","testCookie","testCookie");
        wr.addCookie("www.domain.com","test2","test2");
        wr.addCookie("www.domain.com","test3","test3");
        wr.addCookie("test4","test4");
        wr.addParameter("testParameter","test");
        ServletUtils.log("beginCactus");
    }
    public void testCactus() throws Exception{
        ServletUtils.log("testCactus");
        assertTrue(true);
        assertTrue(request.getParameter("testParameter").equals("test"));
        PrintWriter out = response.getWriter();
        //HttpServletRequest req2 = (HttpServletRequest) request;
        javax.servlet.http.Cookie[] cks = request.getCookies();
        if (cks == null)
            ServletUtils.log("cookies is null");
        else {
            ServletUtils.log(""+cks.length);
            for (int i=0; i < cks.length; i++){
                javax.servlet.http.Cookie ck = cks[i];
                ServletUtils.log(ck.getName());
                ServletUtils.log(ck.getValue());
                
            }
        }
        out.println("testing cactus");
        out.flush();
        out.close();
    }
    public void endCactus(WebResponse wr){
        ServletUtils.log("endCactus");
        assertTrue(hasText(wr,"testing cactus"));
        ServletUtils.log("test2Cactus");
        //org.apache.cactus.Cookie ck = wr.getCookie(ServletUtils.COOKIE_NAME);
        
    }



What I get back in my log is "cookies is null".

There are no cookies in the request that I want to pass to my servlet.  That is a major problem.

I would appreciate help.

Thank you, 

Denis