Databases on the Web - Georgia State University

PL/SQL Server Pages
(Web Programming with PL/SQL)
Erdogan Dogdu
Georgia State University
Computer Science Department
[email protected]
http://db.gsu.edu/~edogdu
Content
Disadvantages of Web Toolkit
 PL/SQL Server Pages
 Syntax
 Loading PSP Pages
 Example

CSC8711
Disadvantages of Web Toolkit
PL/SQL Web Toolkit (htp, htf) generates
HTML code form PL/SQL programs.
 Generating nice web pages is difficult,
you cannot author PL/SQL programs in
Frontpage.
 Solution is PSP (next)

CSC8711
PL/SQL Server Pages (PSP)
Author web pages using script-friendly
HTML authoring tools.
 Drop in PL/SQL code within HTML code
using scripting tag <% %>.
 In short:

– Web Toolkit: generate HTML from PL/SQL
– PSP: embedded PL/SQL within HTML
CSC8711
Syntax of PL/SQL Server Pages
Same script tag syntax as in ASP and
JSP: <% … %>
 PSP files should have .psp extension
 Can be as simple as an HTML page (no
PL/SQL script)
 Specifying the scripting language

<%@ page language="PL/SQL" %>
CSC8711
Syntax of PL/SQL Server Pages

Parameter passing
<%@ plsql parameter="varname" %>

Returned document type
<%@ page contentType="MIMEtype" %>
Such as text/xml, text/plain, image/jpeg

Stored procedure name
<%@ page procedure="procname" %>
CSC8711
Loading PL/SQL Server Pages

Loading psp document to Oracle
loadpsp [ -replace ] -user
username/password[@connect_string] [
include_file_name ... ] [ error_file_name ]
psp_file_name ...
CSC8711
More Syntax

Statements
<% PL/SQL Statement;
[ PL/SQL Statement; ] … %>

Expression
<%= PL/SQL Expression %>

Conditional blocks
<% if condition then %>
[HTML code]
<% else %>
[HTML code]
<% end if; %>
CSC8711
More Syntax

Including files
<%@ include file="path name" %>

PL/SQL declarations
<%! PL/SQL declaration;
[ PL/SQL declaration; ] ...
%>
CSC8711
PSP Example: Grade Book
First page: get_access.psp
Overview: Allows login to application
<%@ page language="PL/SQL" %>
<%@ plsql procedure="get_access" %>
<HTML>
<HEAD>
<TITLE>Get password</TITLE>
<H1>Grade Book Access Page</H1>
</HEAD>
(cont. next slide)
CSC8711
PSP Example: Grade Book
<BODY>
<FORM
ACTION="<%=owa_util.get_owa_service_pat
h%>start_session" METHOD="POST">
<BR>
Today is <%=to_char(sysdate, 'Day')%>,
<%=to_char(sysdate, 'Dd / Mon / YYYY
HH:MI AM')%>
<BR><BR>
(cont. next slide)
CSC8711
PSP Example: Grade Book
<TABLE><TR>
<TD><STRONG>USER ID: </STRONG></TD>
<TD><INPUT TYPE="text" NAME="usid" SIZE="20"
MAXLENGTH="50"></TD>
</TR>
<TR>
<TD><STRONG>PASSWORD: </STRONG></TD>
<TD><INPUT TYPE="password" NAME="passwd"
SIZE="20" MAXLENGTH="50"></TD>
</TR></TABLE>
<INPUT TYPE="submit" VALUE=" Proceed ">
<INPUT TYPE="reset" VALUE="Reset">
</FORM></BODY></HTML>
CSC8711
PSP Example: Grade Book
CSC8711
Form Processing
create or replace procedure start_session(
usid in varchar2 DEFAULT NULL,
passwd in varchar2 DEFAULT NULL) AS
…
begin
select A.userid, A.password,
A.lastAccess, A.authority
into user_buffer, passwd_buffer, time_buffer,
auth_buffer
from users A
where upper(A.userid)=upper(start_session.usid);
…
end start_session;
CSC8711
This form
processing program
does not generate
any HTML code.
Therefore, we leave
it as a PL/SQL
program
(start_session.sql)
Form Processing in PSP

Example:
<%@ page language="PL/SQL" %>
<%@ plsql procedure="teacher_menu" %>
<%@ plsql parameter="u_access"
type="varchar2" default="null" %>
<%@ plsql parameter="userid"
type="varchar2" default="null" %>
…
CSC8711