3、利用WebServer和PL/SQL开发动态Web实例
现有一考生成绩库需在网上向用户提供查询成绩的功能。首先可考虑利用HTP程序包根据用户输入的考生号到数据库中查询相应的信息,返回一个网页。代码如下:
Create or replace procedure score_into_webpage (code_in in number)Ascursor score_cursor isselect code,name,scorefrom studentwhere code = code_in;BeginHtp.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_curLoop--利用游标的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; |
通过以上代码,我们有了一个基本的用数据库中的数据动态的生成一个网页的方法,下面将建立一个简单的表单。在表单中调用上述程序和接受用户输入的考生号码,从而在客户端向用户动态地显示从数据库中查询的信息。