Example of using a cookie in a WAM
|Date:||23 September 2011|
|Product/Release:||LANSA for the Web (WAMs) V12 SP1|
|Abstract:||A simple example to show how to store and retreive a cookie in a WAM|
|Submitted By:||LANSA Technical Support|
- Create a WAM with a webroutine in it and generate the XSL for the webroutine.
- Go to the design view -> XML
- Inside the <lxml:server-instructions> section, add the following cookie information
<lxml:cookies> <lxml:cookie name="TESTC"> <lxml:value field-name="STD_NUM"/> <lxml:expires>Fri 30, Sep 2011 10:00:00 GMT</lxml:expires> <lxml:domain /> <lxml:path /> <lxml:secure /> </lxml:cookie> </lxml:cookies>
- Some notes about the Cookie:
The value of field STD_NUM will be read and stored in the cookie
The cookie value will be placed in the field TESTC the next time the website is executed
Expires could also be left blank. The cookie will then expire when the browser is closed.
- In the webroutine, create web_map (both) for TESTC and STD_NUM
Define Field(#TESTC) Reffld(#STD_NUM) Desc('Cookie name')
e.g Web_Map For(*both) Fields(#std_num (#TESTC *out))
- Switch to Design view -> Web Page.
- Drag and drop from the Webroutine Output tabs the two STD_NUM and TESTC fields onto the page.
- Drag and drop a push button from Weblet Template in the Favourites tab.
- Set the on_click_wrname for the push button to refer to itself (this property controls the name of the web routine to execute when the weblet is clicked)
The way this example works is that the value of std_num will be sent to the server each time the user clicks the button. This value will then be used by the server to generate a cookie to be stored in the client's machine. This cookie will be stored in the Temporary Internet Files directory. The next time the user loads the page, the website will load the value of the cookie onto the TESTC field and it will be shown on the page.