主页程序名为category.asp,另外两个程序名为categorysave.asp和conn.asp,以下给出这三个程序的参考程序。
[category.asp]
<!—#include file="conn.asp"—>
<title)商品大类管理</title>
<table width="98%"border="0"align="center"cellpadding="0"cellspacing="1"bgcolor="#6699cc">
<tr>
<td height="40"bgcolor="#6699cc"align="center"><span style="background—color:#6699CC"><b><font color:"#FFFF00">商品大类管理</font></b></span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="80%”border="0"align="center"cellpadding="1"cellspacing="1"bgcolor="#CCCCCC">
<tr align="center"bgcolor="#FFFFFF"height="20">
<td width="30%">类别名称</td>
<td width="20%">类别顺序</td>
<td width="20%">类别级别</td>
dim follows
if rs.EOF and rs.BOF then
response.Write"<div align=center><font color=red>还没有分类</font></center>"
follows=0
else
do while not rs.EOF
<tr bgcolor="#FFFFFF"align="center">
<td><input name="category"type="text"id="category"size="12"value="<%=trim(rs("category"))%>"></td>
<td><input name="categoryorder"type="text"id="categoryorder"size="4"value="<%=int(rs("categoryorder"))%>"></td>
<td><input name=first type=checkbox value=1>
<%if rs("first")=1 then
response.Write"<font color=red>一级</font>"
else
response.Write"二级"
end if%>
</td>
<td><input type="submit"name="Submit"value="修改">
 <a href="categorysave.asp?id=<%=int(rs("categoryid"))%>
loop
follows=rs.RecordCount
end if%>
</table><br></td>
</tr>
</table>
<br>
<table width="98%"border="0"align="center"cellpadding="0"cellspacing="1"bgcolor="#6699cc">
<tr>
<td height="40"bgcolor="#6699cc"align="center"><span style="backgroundcolor:#6699CC"><b><font color="#FFFF00">添加商品大类<riont></b>
</span></td>
</tr>
<tr>
<td bgcolor="#FFFFFF">
<table width="80%"border="0"align="center"cellpadding="1"cellspacing="1"bgcolor="#CCCCCC">
<tr align="center"bgcolor="#FFFFFF"height="20">
<td width="30%">类别名称</td>
<td width="20%">类别顺序</td>
%td width="20%">类别级别</td>
%td width="30%">确定操作</td>
</tr>
<form name="forml"method="post"action="categorysave.asp?action=add">
<tr align="center"bgcolor="#FFFFFF">
<td><inPut name="category2"type="text"id="category2"size="12"></td>
</tr>
</table>
[categorysave.asp]
<!一#include file="conn.asp"—>
<%dim action,categoryid
categoryid=request.QueryString("id")
rs.AddNew
rs("category"1=trim(request("category2"))
rs("categoryorder")=int(request("categoryorder2"))
rs("first")=int(request("first2"))
rs.Update
rs.Close
rs.open"select*from类别表where categoryid="&categoryid,conn,1,3
rs("category")=trim(request("category"))
rs("categoryorder")=int(request("categoryorder"))
rs("first")=int(request("first"))
rs.Update
rs.Close
set rs=nothing
response.Redirect"category.asp"
response.Redirect"category.asp"
end select
%>
[conn.aspl
<%
option explicit
dim conn,connstr,db,rs
db="客户订货数据库.mdb"
Set conn=Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath
(""&db&"")
conn.Open connstr
%>
<head>
<meta http-equiv="Content-Type"content="text/html;charset=gb2312">
<style>
td{font-size:9pt;line-height:120%;color:#353535)
body{font-size:9pt;line-height:120%)
a:link {color:#000000;text-decoration:none)
a:visited {color:#000000;text-decoration:none)
a:active {color:#000000;text-decoration:none)
a:hover {color:#336699;text-decoration:none;position:relative;right:Opx;top:lpx}
</style>
<STYLE type=text/css>
.pad{
PADDING-LEFT:150px
}
</style>
</head>
<body bgcolor=:#FFFFFF"leftmargin="4"topmargin="4"marginwidth="0"marginheight="O">
注:在一个ASP页中,可以使用#include指令把另一个文件的内容插入到当前的页面中。这条指令读取该文件的全部内容并插入到该页中,替代<!——#include..——>行。这是一种非常有用的插入HTML段落的技术。
通过把脚本和内容分开的方法,给页面提供一个组成层次。这意味着如果对脚本进行了修改,在客户端再次打开该页面时,脚本的修改情况自动地放映到使用包含文件的每一个页面中。例如数据库连接的获取都作为一个单独的模块包含到所有的ASP页面中。
category.asp
<!——#include file="conn.asp"——>
…
conn.asp
…
<%
db="客户订货数据库.mdb"
Set conn=Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="&Server.MapPath(""&db&"")
conn.Open connstr
%>
这样当修改数据库连接时,所有包含conn.asp的页面引用的数据库连接都会得到修改,从而大大减轻了代码开发的工作量,也能更好地保证软件的质量。这也是模块化和降低软件之间耦合性思想的体现。