您现在的位置: 网页制作教程网 >> 数据库教程 >> oracle 教程 >> 文章正文

应用Oracle组件实现动态Web数据库 (1)

作者:hpuje

来源:bc-cn

热度:

2006-10-6 13:37:15

3、利用WebServer和PL/SQL开发动态Web实例

现有一考生成绩库需在网上向用户提供查询成绩的功能。首先可考虑利用HTP程序包根据用户输入的考生号到数据库中查询相应的信息,返回一个网页。代码如下:

Create or replace procedure score_into_webpage (code_in in number)
As
cursor score_cursor is
select code,name,score
from student
where code = code_in;
Begin
Htp.htmlopen;
Htp.headopen;
Htp.title ('Student's score information');
Htp.headclose;
Htp.bodyopen (cattributes=>'bgcolor = "#80800"');
Htp.tableopen(border');
Htp.tablecaption ('Score Information','center');
Htp.tablerowopen;
Htp.tableheader (' Student Code');
Htp.tableheader (' Student Name');
Htp.tableheader (' Student Score');
--固定地显示页标题、标题、表头等信息,每次调用此页时显示的信息
--是相同的
Htp.tablerowclose;
For score_rec in score_cur
Loop
--利用游标的For循环为游标在网页中产生一个数据行
htp.tablerowopen;
htp.tabledata (score_rec.code);
htp.tabledata (score_rec.name);
htp.tabledata (score_rec.score);
htp.tablerowclose;
Endloop;
Htp.tableclose;
Htp.bodyclose;
Htp.htmlclose;
End;

通过以上代码,我们有了一个基本的用数据库中的数据动态的生成一个网页的方法,下面将建立一个简单的表单。在表单中调用上述程序和接受用户输入的考生号码,从而在客户端向用户动态地显示从数据库中查询的信息。

Create or replace procedure ScoreForm
As
Begin
Htp.headopen;
Htp.title ('Code Entry Form');
Htp.headclose;
Htp.bodyopen;
Htp.header (2,'Score Information Code Form');
Htp.p ('
');
Htp.formopen ('Score_into_Webpage',cmethod=>'GET');
--打开ScoreForm表单。缺省情况下Score_into_webpage PL/SQL过程用GET
--方法调用。GET方法在URL里显示传递的参数。
Htp.tableopen ('border');
Htp.tablerowopen;
Htp.tabledata ('Enter Student Code');
Htp.tabledata (htf.formtext ('code_in',5,5));
--用一个文本框提示用户输入考号。文本框的名字必须与调用过程里的输入
--参数相同。
Htp.tablerowclose;
Htp.tablerowopen;
Htp.tablerowclose;
Htp.tablerowopen;
Htp.tabledata (htf.formSubmit);
Htp.tabledata (htf.formReset);
Htp.tablerowclose;
Htp.formclose;
Htp.bodyclose;
Htp.htmlclose;
End;

上述过程在客户端被调用后产生的HTML即可显示一动态表单接受用户输入的考号,然后传递给调用的过程score_into_webpage,从而到Oracle DBServer中查询出所需的数据,再通过该过程动态生成的HTML在Web浏览器中显示出来。

4、 结束语

作为一个大型数据库服务器,Oracle提供了一个面向网络的开发工具、应用服务器和数据库服务器的综合平台。本文利用其标准PL/SQL和内置程序包并结合WebServer讨论了基本的动态Web的开发和应用。

上一页  [1] [2] 

我来说两句:

1分 2分 3分 4分 5分
姓名: *


* 请各位网友遵纪守法并注意语言文明。
网站简介 | 联系方式 | 意见建议 | 版权说明
Copyright © 2007 All rights reserved
滇ICP备06006992号