 |
|
Oracle Database Tips by Donald Burleson |
APEX and OWA_COOKIE
The Oracle Web Agent (OWA) packages are not part
of the APEX installation, but they do warrant some coverage since
APEX uses them. They are further documented in Oracle document
B10802. The name of the document is PL/SQL Packages and Types
Reference. It is a huge document and a valuable asset to which
developers and programmers should have ready access. The document can
be found by using the link at the top of the chapter.
The OWA_COOKIE package deals with browser
cookies. It will write to a cookie and read from a cookie stored on
the client machine. If no date is specified, the cookie only exists
during the client's session.
Types used with the OWA_COOKIE package
type vc_arr
is table of varchar2(4000)
index by binary_integer.
type cookie
is record (
name varchar2(4000),
vals vc_arr,
num_vals integer);
owa_cookie.send(
name in varchar2,
value in varchar2,
expires in date default null,
path in varchar2 default null,
domain in varchar2 default null,
secure in varchar2 default null);
This creates a cookie on the client browser
machine. The expires date should be specified or the cookie only
exists during the life of the session.
Example:
begin
owa_util.mime_header('text/html', FALSE);
owa_cookie.send(
name=>'EASY_COOKIE',
value=>lower(:P2100_COOKIE_SOURCE),
expires => sysdate + 365);
-- Set the
cookie and redirect to another page
owa_util.redirect_url(
'f?p=&APP_ID.:2101:&SESSION.' );
exception
when others then
null;
end;
get( name in varchar2) return cookie;
This will return a type of cookie as explained
earlier. It receives the name of the cookie to return.
Example:
declare
v varchar2(255) := null;
c owa_cookie.cookie;
begin
c := owa_cookie.get('LOGIN_USERNAME_COOKIE');
:P2100_COOKIE_TARGET := c.vals(1);
exception
when others then
null;
end;
owa_cookie.remove(
name in varchar2,
val in varchar2,
path in varchar2 default null);
This procedure forces the cookie to expire, which
essentially removes its availability to be used. It does this by
setting the expiration date to 01-JAN-1990.
Example:
begin
owa_cookie.remove(
name => 'EASY_COOKIE',
value => NULL);
end;
print_cgi_env
This prints all CGI environment variable's
available to the CGI Gateway. This procedure can be placed directly
in a PL/SQL region to display the values of all the CGI variables.
Put the following code in the PL/SQL region:
print_cgi_env;
The above book excerpt is from:
Easy HTML-DB
Oracle Application Express
Create
Dynamic Web Pages with OAE
ISBN 0-9761573-1-4
Michael Cunningham & Kent Crotty
http://www.rampant-books.com/book_2005_2_html_db.htm |