<!-- Enhydra Java Application Server Copyright 1997-1999 Lutris Technologies, Inc. All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 3. All advertising materials mentioning features or use of this software must display the following acknowledgement: This product includes Enhydra software developed by Lutris Technologies, Inc. and its contributors. 4. Neither the name of Lutris Technologies nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY LUTRIS TECHNOLOGIES AND CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL LUTRIS TECHNOLOGIES OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. --> <JDDI JAVAIMPORT> import javax.servlet.http.Cookie; import demoApp.DemoApp; </JDDI> <JDDI INCLUDE="../jinc/Setup.jinc"></JDDI> <JDDI JAVADEF> public void DisplayAndSetCookie(JoltPage page) throws Exception { DemoApp application = (DemoApp)page.application; Cookie[] cookies = page.request.getCookies(); for (int i=0; i<cookies.length; i++) { page.append("<CENTER><FONT FACE=\"Arial,Helvetica\">" + cookies[i].getName() + " = " + "<B><FONT COLOR=red>" + cookies[i].getValue() + "</FONT></B>" + "</FONT></CENTER><BR>"); } /** * Set Demo cookie... */ Integer randomNumber = new Integer (application.randomNumberGenerator.nextInt()); Cookie cookie = new Cookie("Demo", randomNumber.toString()); page.response.addCookie(cookie); } </JDDI> <HTML> <HEAD> <TITLE>JDDI HTML Example: Cookies</TITLE> </HEAD> <JDDI INCLUDE="../jinc/Header.jinc"></JDDI> <BODY> <CENTER> <B><FONT FACE="Arial,Helvetica" SIZE=+3> Setting Cookies </FONT></B> </CENTER> </BODY> <JDDI INCLUDE="../jinc/Buttons.jinc"></JDDI> <JDDI INCLUDE="../jinc/Home.jinc"></JDDI> <BODY> <BR> <CENTER> <TABLE COLS=1 WIDTH="60%"> <TR> <TD> <FONT FACE="Arial,Helvetica" SIZE=+1> This page displays and then resets a cookie called "Demo" to a random number. If this is your first visit to this page, you will only see the "DemoApp" cookie. The "Demo" cookie will not yet be set. Reload the page to view the "Demo" cookie. Then, turn on debugging to see how the response object contains the cookie on exit. </FONT> </TD> </TR> </TABLE> </CENTER> <BR> <JDDI HTML IFEQ FIELD=cgiArgs.help VALUE="on"> <CENTER> <TABLE COLS=1 WIDTH="40%" > <TR> <TD> <FONT FACE="Arial,Helvetica" COLOR=red> This page is set up to set the "Demo" cookie to a new value on reload. The "DemoApp" cookie, is your session cookie, and will remain the same on reload. </FONT> <CENTER><IMG SRC="../media/arrow.gif" BORDER=0 ANCHOR=BOTTOM></CENTER> </TD> </TR> </TABLE> </CENTER> </JDDI> <JDDI JAVACALL=DisplayAndSetCookie></JDDI> <BR> <JDDI HTML IFEQ FIELD=cgiArgs.debug VALUE="on"> <CENTER> <TABLE COLS=1 WIDTH="40%" > <TR> <TD> <FONT FACE="Arial,Helvetica" COLOR=red> Before the Demo cookie is set in the page, the request & response objects look like this: </FONT> <IMG SRC="../media/arrow.gif" BORDER=0 ANCHOR=BOTTOM ALIGN=LEFT> </TD> </TR> </TABLE> </CENTER> </JDDI> <JDDI JAVACALL=JoltDebug.displayRequest IFEQ FIELD=cgiArgs.debug VALUE="on"></JDDI> <BR> <JDDI HTML IFEQ FIELD=cgiArgs.debug VALUE="on"> <CENTER> <TABLE COLS=1 WIDTH="40%" > <TR> <TD> <FONT FACE="Arial,Helvetica" COLOR=red> After the Demo cookie is set in the page, the request & response objects look like this. Notice the response object: </FONT> <IMG SRC="../media/arrow.gif" BORDER=0 ANCHOR=BOTTOM ALIGN=LEFT> </TD> </TR> </TABLE> </CENTER> </JDDI> <JDDI JAVACALL=JoltDebug.displayRequest IFEQ FIELD=cgiArgs.debug VALUE="on"></JDDI> </BODY> </HTML>