Creating Cookies - Websphere

This is a discussion on Creating Cookies - Websphere ; Hi, I have HTTPRequest/Response object in the struts action class. And I wanted to create a cookie, say, new Cookie ("userCookie",userAccVOFromSession.getUserId()) I tried like this, httpResponse.addCookie(new Cookie ("userCookie",userAccVOFromSession.getUserId())); But when I tried to retrieve the cookie with getCookie method, I ...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Creating Cookies

  1. Creating Cookies

    Hi,



    I have HTTPRequest/Response object in the struts action class. And I wanted to create a cookie, say,



    new Cookie ("userCookie",userAccVOFromSession.getUserId())


    I tried like this,


    httpResponse.addCookie(new Cookie ("userCookie",userAccVOFromSession.getUserId()));


    But when I tried to retrieve the cookie with getCookie method, I am getting only LTPA and JSession cookie which were set as default.



    Can anyone help as how to create a cookie? Is there any specific procedures for IBM WebSphere Portal?


    Thanks in advance,

    Suren

  2. Re: Creating Cookies

    are you in a jsr 168 portlet? if so you cannot set cookies there




    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

  3. Re: Creating Cookies

    jwbarnes wrote:

    are you in a jsr 168 portlet? if so you cannot set cookies there




    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

    Yes Jim.. It is Struts + JSR 168 portlet based. Are there any alertnatives to set the user defined cookies?

  4. Re: Creating Cookies

    not without doing some kind of hack, because this is what the spec states



    The following methods of the HttpServletResponse must perform no operations:

    setContentType, setContentLength, setLocale, addCookie, sendError,



    So you could do it in the theme or something like that, if you were on a page that new it needed to set something



    IBM Certified System Administrator -- WebSphere Portal V6.0, V5.1, V5.0

    IBM Certified Solution Developer -- WebSphere Portal V5.1, v6.0



    The postings on this site are my own and do not necessarily represent the positions, strategies, or opinions of IBM

  5. Re: Creating Cookies

    Hi,



    I tried in the themes as said above. Tried including the cookie code in footer.jspf file like below,



    %
    System.out.println( "Trying to Retrieve cookies" );

    boolean foundCookie = false ;
     
    Cookie[] cookies = request.getCookies();

    for ( int i = 0; i cookies.length; i++) {
    Cookie c = cookies;
    if (c.getName().equals( "userCookie" )) {
    System.out.println( "Cookies Searched" );
    out.println( "cookie name= " + c.getName() + " cookie Value : " + c.getValue());
    foundCookie = true ;
    }
    }
     
    if (!foundCookie) {
    System.out.println( "Cookies Created" );
    Cookie c = new Cookie( "userCookie" , "Test Value" );
    out.println( "cookie name= " + c.getName() + " cookie Value : " + c.getValue());
    response.addCookie(c);
    }

    System.out.println( "Once Again getting the cookies" );
    Cookie[] cookiesDuplicate = request.getCookies();

    for ( int i = 0; i cookiesDuplicate.length; i++) {
    System.out.println( "Cookies Searching for Second time" );
    System.out.println( "cookie name= " + cookiesDuplicate.getName() + " cookie Value : " + cookiesDuplicate.getValue());
    }



    Still, while retrieving the cookies, i am able to see only the LTPA and JSESSION in Sysout log file. I am also pasting that piece of sample from Sysout log file,



    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O Trying to Retrieve cookies
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O Cookies Created
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O Once Again getting the cookies
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O Cookies Searching for Second time
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O cookie name= LtpaToken cookie Value : DLypIj349dBrwmETgTQQKxEdvQeWWFcJTs4pBnTGwlxnOO1+KX qg/tfOOf0hceTiEImMWfdxo4Iho+yl/n8BE84xL4qLQFNY11hKhx0XmfKxb5Ll97lQP0FhfFvFyGgjWm4 8/Pi24YBZ8tZDclaqH/JSJNSUt/b4hM7hseusGvl5+16EFHbuRLofCJKQ4xa/iteIjxKDW3eqkCqLk46zXZrVGaZP1YLPKMDUxCk8RULosu8ars z0YfIZf24wr/JN63fGbth/Bj6KLgU2PggQiRhGZFMEDbSCBk5uiFj4g8IeJRrmwDQ70bYVOA 0yjMUpZ0p/ZRFJ1GwiRDLQdPwSn7SXXbeRQ5xu7TKUjGUloIFjIASYZEj58Z aMmf2xp3TQ
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O Cookies Searching for Second time
    [6/23/08 12:47:02:797 IST] 0000004f SystemOut O cookie name= JSESSIONID cookie Value : 00006hkOEN4bBRdFg9TahIaZTPi:-1





    Can anyone help whether i am missing anything during the creation of cookies?


    Thanks in advance,

    Suren

+ Reply to Thread