response重定向后为何无法调用过程而能直接使用代码(展开的过程)
conn.asp
<%
Option Explicit
On Error Resume Next
Dim rs,conn,connstr,dbpath
dbpath="database/exam.mdb"
Set conn = Server.CreateObject("ADODB.Connection")
connstr="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(dbpath)
conn.Open connstr
If Err Then
response.write "<font size=""4"">·数据库连接错误....</font>"
response.End
End If
sub closeDb()
if not conn is nothing then
if not rs is nothing then
rs.close
Set rs = nothing
End if
conn.close
Set conn = nothing
End if
End sub
%>
我在test.asp文件处如下调用
<!--#include file="conn.asp" -->
<%
closeDb()
response.Write("<script>javascript:location='reg.asp';</script>")
%>
访问test.asp后,跳转至reg.asp(reg.asp不曾连接数据库),发现与数据库的连接不曾关闭
改动test.asp如下(把过程直接展开)
<%
response.Write("<script>javascript:location='reg.asp';</script>")
if not conn is nothing then
if not rs is nothing then
rs.close
Set rs = nothing
End if
conn.close
Set conn = nothing
End if
%>
访问test.asp后,跳转至reg.asp,且与数据库的连接正常关闭,展开的过程不论放在重定向前面或后面,都不影响效果
不明白其中原委,特来求助