cancel
Showing results for 
Search instead for 
Did you mean: 

using server-side cookies to store data in a non mvc application

Former Member
0 Kudos

Hi

I am trying to understand the use of server-side cookies in a non mvc base application with single page. I have an auto attribute in page called 'count' which I am increamenting on OnInputProcessing().

In OnRequest() I am getting the server-side cookie using 'CALL METHOD CL_BSP_SERVER_SIDE_COOKIE=>GET_SERVER_COOKIE' and take value of count from that and display that on my layout.

In OnManipulation() I am setting the value of count back to the cookie using ' CALL METHOD CL_BSP_SERVER_SIDE_COOKIE=>SET_SERVER_COOKIE'

My problem is the value of count set to '0' when I am accessing it. then after subsequent click on button the value remains at '1'. i.e. It increaments only once.

On debugging I found that when it reaches OnRequest() the value of count becomes '0'.

can you explain why & what need to be done to overcome this.

Thanks & regards

Ashutosh

Accepted Solutions (0)

Answers (1)

Answers (1)

eddy_declercq
Active Contributor
0 Kudos

Hi,

My first thought would be that you should set the cookie at the place (thus oninputprocessing) wher you increment the count variable. Can you show some more code in order to understand better the problem pls?

Eddy

Former Member
0 Kudos

sure Eddy, here are they

OnRequest()->



  DATA: page_data TYPE XSTRING.
  DATA: name TYPE STRING.

* User Management can be using normal ABAP sy-name or other technique.
  name = sy-uname.

* First get server side cookie
  CALL METHOD CL_BSP_SERVER_SIDE_COOKIE=>GET_SERVER_COOKIE
    EXPORTING
      NAME                  = 'data1'
      APPLICATION_NAME      = runtime->application_name
      APPLICATION_NAMESPACE = runtime->application_namespace
      USERNAME              = name
      SESSION_ID            = runtime->session_id
      DATA_NAME             = 'page_data'
    CHANGING
      DATA_VALUE            = page_data.

* From server side cookie, restore all "persisted" page attributes
  IF page_data IS NOT INITIAL.
    IMPORT count = count
           FROM DATA BUFFER page_data.
  ENDIF.

OnManipulation()


  DATA: page_data TYPE XSTRING.
  DATA: name TYPE STRING.

* User Management can be using normal ABAP sy-name or other technique.
  name = sy-uname.


  EXPORT count FROM count
        TO DATA BUFFER page_data.

* First get server side cookie
  CALL METHOD CL_BSP_SERVER_SIDE_COOKIE=>SET_SERVER_COOKIE
    EXPORTING
      NAME                  = 'data1'
      APPLICATION_NAME      = runtime->application_name
      APPLICATION_NAMESPACE = runtime->application_namespace
      USERNAME              = name
      SESSION_ID            = runtime->session_id
      DATA_NAME             = 'page_data'
      DATA_VALUE            = page_data  .
[/code}

OnInputProcessing()->

[code]add 1 to count.

Former Member
0 Kudos

Sorry Eddy, I have forgot to make the application stateful, now its working fine. Thanks for your response.

eddy_declercq
Active Contributor
0 Kudos

If you set to stateful, you don't need to set/get any cookies.

former_member181879
Active Contributor
0 Kudos

Make application stateless, and change the follow line:


Old: SESSION_ID = runtime->session_id
New: SESSION_ID = 'any constant string'

I suspect your browser is rejecting you appcontext cookie. Eddy has a good weblog on this.

eddy_declercq
Active Contributor
0 Kudos

In case you don't find it, it's at /people/eddy.declercq/blog/2005/01/13/the-unfortunate-cookie

Former Member
0 Kudos

Yeah It is working now,

Thanks everyone for the response.

regards

Ashutosh

eddy_declercq
Active Contributor
0 Kudos

Cheers.

Don't forget the reward points in case you didn't already;-)