Using Cookies

Hi there
I have a report template, inside of which is a div containing drop down boxes. I want to use a button to hide/show the div.
The code to do that is quite simple, however, I want to be able to 'remember' the view state of the div with subsequent page refreshes ( as happens when a value is selected from the drop down ).
I thought I could use client-side cookies to achieve this, and for the most part this works.
However, the first time I set the cookie, it doesn't seem to save the value.
So, the process behind the scenes, is as follows:
1. Enter the page for the first time ... cookie doesn't exist and div is hidden
2. Click on the SHOW button, which sets the cookie to visible, and displays the div.
3. Select a value from one of the dropdowns in the div, which reloads the page.
4. As the page loads, the cookie should be read and the div display, but I find that the cookie is null or doesn't exist. If I now follow steps 2 and 3 again, next time the page loads, the cookie is read.
So ... the cookie doesn't seem to be set on the first action, but does work correctly on subsequent actions ... very confusing ??
Any ideas?
Cheers,
Andrew

Hi,
You can find the info on how to use cookies here:
http://java.sun.com/developer/onlineTraining/Programming/JDCBook/aucserv.html
Hope this helps you
Cheers
Giri :-)
Creator Team

Similar Messages

  • How do I use cookies to control which part of the timeline to play from?

    Hi there,
    I have created an animation with Adobe Edge. My site uses Concrete5 and I am pulling in the Edge content into an IFRAME on my home page (there my be a better way to do this and I'm open to suggestions). I want the animation to play from the start when someone first visits the site, but if during their browser session they navigate back to the home page, I want the animation to only play a shorter segment of frames near the end.
    My question is, how do I use cookies to acheive this? I'm new to javascript/jquery.
    I've included the following code on compositionReady, (found in another post on this forum) but don't have a clue how to continue...
    // insert code to be run when the composition is fully loaded here yepnope(   {     nope:[       '/js/jquery.cookie.js'     ],   complete: init   } ); function init() { //create your cookie's initial values here } 
    My temp site is here - http://79.170.40.43/nutcrackerdesign.co.uk/
    On revisting the homepage, I only want to play from when the green 'How can we help?' button drops in.
    Many thanks!
    Russ

    Hi, Russ-
    I found this article, which seemed really helpful in describing how cookies work in JavaScript:
    http://www.quirksmode.org/js/cookies.html
    Remember that JS works just fine within Animate, so on your compositionReady, you can read your cookie and then set the play based on that.  You should probably uncheck the autoplay for your Stage and control the play of your Stage from the compositionReady.
    Good luck!
    -Elaine

  • Using cookies and JavaScript to create a page to page timer.

    I have long wanted to be able to measure the time it takes to get from one page to another.  While reading in my JavaScript reference the other day, I came across cookies.  I've long known about cookies but have never used them.  The thing that looked attractive was that you can access cookies from both JavaScript and CF.
    So I put together the procedures to store the "start time" (startTimeP8D) for the transition and activated it on the onUnload event of a 1stpage.  After a few rewrites I got it working.   Here is the JavaScript to do that: it consists of two functions: doTimer which is the input section and setCookie, which writes to the cookie.  Not the two numbered alert statements.
    doTimer - results for "start" from the doTimer function called from page 1 when it unloads. (See doTimer below)
         Please note that the two startTime8D values are the same immediately after they are stored.
    On the 2nd page in the sequence, I run the corresponding code to determine the "end time", compute the delta and write it out to the page.  It didn't all run on the first try, but it now seems to be running without a crash, which can be misleading.
          second set of outputs from page 2:    
         Please not that while the endTimeP8D match, the startTimeP8D value no longer matches the previously stored value. 
    There is one major hitch in the get along which has me stymied:  As you can see, when you compare the startTimeP8 in the setCookie – results above and the "startTimeP8" in the doTimer results below the startTimeP8 is not the value that I wrote to the cookie @ unload of page 1.  I have checked and checked and do now see anywhere that the startTimeP8D value is being overwritten.  Based upon my limited experience with JavaScript cookies, it seems to me that you get an entry for each time you set the cookie.  So I would expect to see to startTimeP8D entry for each setCookie event, not a different value.
         The result of the failed computation is shown on the bottom of the page.  As you can see, the Total Elapsed Time is negative, which is never a good sign.  The other time shown, Page build time, is the run time from the server.  The whole purpose is to be able to show folks that the reason the code might be show is because of their overloaded network and not our code.  We had one client whose had users running on 56k modems.  It was so slow their VPN software was timing out!!!  Still the had the never to blame us!!!
    I am using SQLServer 2005, CF8, IE8 on W7. 
    I'm not married to this way of doing this so if anyone has a better/easier way of doing a "page to page timer", I'm up for it.  I'd prefer to fix this one since I've been working on it for the past 3 days.
    Thanks in advcance for your help.
    Len, PHRED SE

    Here it is with no JQuery or console logging calls using cookie utility functions found here:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
           "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
         <title>Test JavaScript Page Load Timer</title>
         <script>
              window.onload = function(){
                   var previousPageUnload = getCookie('unloadTime');
                   if(previousPageUnload){
                        var d = new Date();
                        var loadTime = d.getTime() - previousPageUnload;
                        alert(loadTime + 'ms');
              window.onunload = function(){
                   var d = new Date();
                     setCookie('unloadTime',d.getTime());
              function setCookie(c_name,value,expiredays) {
                   var exdate=new Date();
                   exdate.setDate(exdate.getDate()+expiredays);
                   document.cookie=c_name+ "=" + escape(value) + ((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
              function getCookie(c_name) {
                   if (document.cookie.length>0) {
                     c_start=document.cookie.indexOf(c_name + "=");
                     if (c_start!=-1)
                       c_start=c_start + c_name.length+1;
                       c_end=document.cookie.indexOf(";",c_start);
                       if (c_end==-1) c_end=document.cookie.length;
                       return unescape(document.cookie.substring(c_start,c_end));
                   return null;
         </script>
    </head>
    <body>
         <h1>Test JavaScript Page Load Timer</h1>
    </body>
    </html>
    Note that overwriting global window events like this is not a good idea, which is why I used JQuery in my earlier example. I strongly suggest you look at JQuery or one of the other JS libraries (YUI, etc.) to help with event handling. I'll leave it at that as this is getting into JavaScript development, not really on topic for a ColdFusion forum.

  • How to use cookies in jsp

    Hi all,
    I'm new to jsp, please let me know how to use cookies with jsp.
    I have three web applications, in run time I have to switch from one application to another application based on single login page. I have taught cookies are one of the solution. But while I'm googling I unable to get such a good material.
    please give some examples,
    Thanks in advance.
    achchayya

    Read a cookie in jsp
    HttpSession session = request.getSession();
    Cookie cookie_session = getCookie(request, "COOKIENAME");
              if (cookie_session == null) {
                   sesID = session.getId();
              } else {
                   sesID = cookie_session.getValue();
              }or
    get all cookie in the browser
    This gets all the cookies and according to the cookie name given u can get the cookie value
    Cookie[] cookies = request.getCookies();
              if (cookies != null) {
                   for (int i = 0; i < cookies.length; i++) {
                        if (cookies.getName().equals(cookieName))
                             return cookies[i];
                   }but i am not sure if this works for ur requirement try and see                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to use cookies in struts

    hai
    iI am new to struts. I want to get value in text field from one form to another using cookis in struts, can any one help me?, please...

    To write a cookie in Struts, you create one and add it to the response object. (response.addCookie(cookie)).
    To read it, you use the bean:cookie tag.
    As to use cookies to get a given value from one form to another, there might be better ways, like using request attributes.
    You might be better off keeping those cookies in the jar, after all.

  • How to use Cookies in Web DynPro?

    Hello,
    Is there a way to use Cookies in Web DynPro like a regular Servlet uses in it's response Object?
    If yes, I could use a code example...
    Roy

    Hi Roy,
    1. This will create a Request Objec containing all the client's request just like in a regular Servlet or does it have special considerations I should worry about?
    A: If you have portal and webdynpro components, both have to use the same runtime. If you are using only webdynpro components then you can use the "Task" class. But it is a non-standard API.
    Task.getCurrentTask().getWebContextAdapter().getHttpServletRequest()
    2. Where do you recommend putting this statement? I assume at the wdDoInit() method right?
    A: Don't put this statement in the doInit(), if you are handling some event within the component and refreshes the view, your doInit() will not get executed.
    3. Is there a Response object I can create as well?
    A:
    HttpServletResponse response =((com.sap.tc.webdynpro.services.sal.adapter.core.IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletResponse()
    Regards,
    Santhosh.C

  • How can I use cookies in Web Content Overlays?

    I have a survey created with Google Docs. It uses cookies to tell if a user has already submitted an answer to a survey.
    It seems to me that these cookies are not stored with web content overlays (I've used the direct URL to the survey as input).
    Am I right? Is there a way to make the cookie thing work?
    br, Simon

    Hi,
    Is this procedure still available in 9iAS and RDBMS 8.1.6 ? I am trying to get it to work, and I keep getting "ORA-00942: table or view does not exist". The owner of this package is "SYS". I even tried prefixing the table name in the SQL string passed to calendarprint with the owner, and it still gave me this error. Does this have anything to do with the invoker rights model ? I need to set up a web calendar and would love to use this functionality...
    What gives ?
    Any help would be appreciated.
    Thanks you

  • Please help me-it's urgent,maintaining session and security using cookies.

    hi folks,
    i presently developing a web site for an engineering colleege ,i am facing prob in maintaining the session using cookies,and destroying a cookie and keeping security to the user,There are four links on my webpage ,including a logout link,when i click the other links other than the logout,it works perfectly,and when i click the logout link,i am not able to disable the cookie and still able to visit previous pages by clicking the back button.please give a suggestion as such to disable the cokie and maintain the security for my web site.
    Thank u....

    Try out this login if it helps you.
    Create a bean that stores some String value. Then make a object of this bean using the useBean tag with session scope when a user logs in. Store the name of the user in the bean and also set the same name value in the Session object. Then on every JSP page compare the value set in the session object with the bean variable (which will be having a session scope). If the value match, then the JSP page output must be displayed to the user. Then on the logout link, invalidate the session object using the invalidate() method of the session class. As a result now when you will try to navigate back to the old JSP page, null will be returned to you when you will try to retrive the name value from the session object. And since this null will not match with the value in the bean, you should not proceed further with generating the output. Hope this help
    Nirav ([email protected])

  • How to use cookie in OAF?

    Hi,
    I want to set cookies from OAF controller.
    Any thought or code snippet?
    Abdul Wahid

    Thanks keerthi,
    Late reply.I guess, the article is about how oaf foundations is maintaining states.
    I did try search, but didn't get any direct solution to use cookies just like its used in servlets.
    The requirement was to maintain session information above the user level sessions. Custom servlet cookies looked fine, but couldn't get way to set those in OAF.
    However, if some body gets similar requirement, the solution found, was, "pageContext.putSessionValueDirect" method.
    Thanks again brother.
    Abdul Wahid

  • Bug in Presentation services - using cookies for GET requests

    Hi,
    I am implementing OBIEE bridge to integrate report in to 3rd party web applications.
    I am creating page using the following syntax:
    *string pageId = htmlViewService.startPage(new StartPageParams() { dontUseHttpCookies = true }, sessionId);*
    Even though its clearly stated not to use Cookies, my guess is that below request is failing because it is expecting cookies:
    http://localhost/Bridge?RedirectURL=saw.dll%2fuicomponents/common/common.xml?fmapId=KqIJCw
    returns with the response
    OBIPSNotLoggedIn
    I have tried to inject all headers and all cookies in the request, but its not helping. Can someone help me in this?
    I will really appreciate any help.
    Thanks!

    Irrespective of building EVALUATE expression (using constant only) in the RPD BMM logical column or just in Answers there are some rules:
    1. RPD/Answers
    If you want to query just EVALUATE expression without some other column then this is must do (example):
    Column1:
    case when 1=2 then PRODUCTS.PROD_CATEGORY else EVALUATE('TO_CHAR(%1)' as char, 100) end
    Evaluate is using only constant. We place presentation attribute inside the case to make navigator to handle this request.
    2. Answers
    You can use only EVALUATE('TO_CHAR(%1)' as char, 100) in the Answers column expression but only in combination with another presentation attribute, cannot have only EVALUATE('TO_CHAR(%1)' as char, 100) in the request.
    Column1: PRODUCTS.PROD_CATEGORY
    Column2: EVALUATE('TO_CHAR(%1)' as char, 100)
    Regards
    Goran
    http://108obiee.blogspot.com

  • Why to use Cookies ?

    why to use Cookies ?

    Hi,
    That doesn't really help. The term Cookie can mean a number of things both in programming terms and in real life. I'm going to guess that you are referring to connecting to SAP Business One where the connection details are passed from the UI API to the DI API by means of an encrypted string. SAP refer to this string as a cookie in the SDK documentation. If this is the cookie that you are asking about then it is only used to pass the connection details from the UI API to the DI API when you are connecting an add-on. This is referred to as the single sign-on method. This is the only time that you need to use this cookie. Search the SDK documentation for Single Sign-On for more details.
    Kind Regards,
    Owen

  • How to define and use cookies so that same login is used on all application

    Hi
    I have 3 apps in a single workspace and all of them SSO enabled
    However when I go from one apps to other, it ask for login again
    I have read in the forum that we can use cookies so that we use the single login on all apps within the same workspace
    But I'm not sure how to define and use cookies.Please assist

    See this presentation:
    http://www.sumneva.com/apex/f?p=15000:395:0::NO::P395_PRESENTATION_KEY:MANY_TO_ONE

  • Use cookies or sessions or what?

    I am using frames on Web Site One, with a frame on Web Site
    One pointing to Web Site Two (I own both web sites).
    Problem: Web Site Two needs remember variables in the Web
    Site Two frame displayed on Web Site One.
    When I use cookies on Web Site Two, they work fine when
    actually on Web Site Two. But cookies will not work in the Web Site
    Two frame on Web Site One.
    I have tried using cfcookie with the domain setting, but it
    doesn't work... probably because they are completely different
    URLs.
    I have tried using session variables, which also work on Web
    Site Two when on that web site, but not when accessing Web Site
    Two's pages in a frame on Web Site One.
    Is there a way to retain variables within a frame on Web Site
    One that is pointing to a completely different URL? Again, I have
    complete access to the coding on both web sites.

    Only if you pass the variable in a url in that frame.
    Sessions and Cookies (
    in many cases the same thing) are domain specific, and not
    only would this not be allowed security-wise by the browser, but CF
    will attempt to stop it as well.
    What you are attempting is basically cross-site scripting.
    Passing a variable to the url of each fram ewould be the only
    way to send the same variable to a completely different website.

  • Use Cookies =  no issue

    I am running a web agent application(web agent 9.2.1) on application server 10g. In the web module on AS: I have changed the property Use Cookies = NO (which is a setting needed for our application ), When running my application I get the following error
    *An error occurred in the Oracle OLAP Web Agent
    *The session is no longer available. It may have been terminated because it was idle
    too long
    Has anyone ecnountered this error, or has an idea on how I could fix it.
    Thanks
    Ahmed Hafez

    Is this on a device? If so, sign out then sign back in again.

  • Preserving link and default state using cookies

    Hello,
    I am not sure where to post this with the re-design of this forum; it's been a while so please forgive me if this is in the wrong g place.
    I have a very basic link wrapped in a UL tag.
    I am using JQuery to give the links a color when they are clicked by performing an add/remove class function, the link state is than preserved by cookies so if a user returns to a page; it shows what tab they were viewing.
    The problem is; this is a single page and I want to set a default link or tab; say the first one. I do not know how to do this.
    This is what I am looking to accomplished:
    A user visits the page and the first link is colored red (default)
    If the user clicks on another link that link becomes active and the first link looses it's default status
    When the user returns the first link is nolonger the default, it is whatever link the user selected when first visited; that's because that link was rememberd using cookies.
    The first link will ONLY maintain the default state if the user deletes his cookies or visits the page for the first time.
    Here is a peice of JQuery I have used to maintain the selected state:
    $(document).ready(function() {
        var idActive = $.cookie('cookieActive');
        if (idActive) {
            $('#'+idActive).addClass('activeLink');
        $('ul li a').click(function() {
            var id = $(this).attr('id');
            $("ul li a").removeClass("activeLink");
            $(this).addClass("activeLink");
            $.cookie('cookieActive', id);
            $.cookie('cookieActive', id, { expires: 10000});

    Good day Mr. Powers!!
    Thank you as always; you are so helpful.
    I am editing this post because I did not get this to work due to my error with applying the ID.
    It is working now and thank you so much!
    By the way any more PHP books in the works?
    DR
    Code is now working with selecting default tab.

Maybe you are looking for

  • How to get the cleaner thread to run

    Hi, I googled documentation/ previous posts, but the topic about getting the log files cleaned is still unclear to me. I have created around 24000 records and then deleted all of them ( ie., there is'nt even a single active record in the database). H

  • Mini Causes Computer Problems

    I have been having problems with my Ipod Mini for awhile now, and now I cannot even hook it up to the computer. Whenever I hook my Mini up to my computer it says that my ipod needs to be restored. However, I cannot restore it because whenever my Ipod

  • Sent to Signature service

    Caro colegas, Temos uma nota que saiu do GRC e esta com o status '02'.  Entrei la no XI e na transacao SXMB_MONI vi a menssagem la que foi enviado ao SIGNN_SignNFe_OB. O status esta com uma bandeira de chadrez e logo depois com um '?' verde.  No outb

  • Logging buffered not working

    Hello: In an ACE  module multicontext environment the buffered logging is not working on the last context I created. The same config though works well for another context. The maximum size and the buffer size is showing 0 in the "show logging" below:

  • High waits on log file sync

    Dear Experts, There is a huge wait on log file sync. I have 5 redo log groups 3 members each. I suspect writing to one group which is hosted on /proddb is taking time. Is there a way we can identify and control this. DB is on 10.2.0.4 OS is RHEL 5