If I want to add or update a cookie is this the correct way of doing it?

    private void updateCookies()
    {
        updateCookie( "HOST", host );
        updateCookie( "METRO", metro );
        updateCookie( "OPERATION", oper );
        updateCookie( "LAYER", layer );
    }

    private void updateCookie( String name, String value )
    {
        Cookie cookie = null;
        cookie = getCookie( name );
        if( cookie == null )
            res.addCookie( new Cookie(name, value) );
        else 
            cookie.setValue( host );
    }
    private Cookie getCookie( String name )
    {
        Cookies[] cookies = req.getCookies();
        for( int i = 0; i < cookies.length; i++ )
        {
            if( cookies[i].getName().equals(name) ) return cookies[i];
        }
        return null;
    }

What I would like to happen is that if the cookie doesn't exist then it
get's created, otherwise the cookie is updated with the new value.  Should
this update the cookie on the client side correctly?

Also, any suggestions about doing the cookie thing.  Anything, I should be
careful of -- should I be using setPath() to make these cookies "non-global"
so to speak?

--
To unsubscribe:   <mailto:[EMAIL PROTECTED]>
For additional commands: <mailto:[EMAIL PROTECTED]>
Troubles with the list: <mailto:[EMAIL PROTECTED]>

Reply via email to