Abstract: This article describes how to dynamically include ASP files in ASP and Make ASP classes instantiated.
In ASP, include file/virtual is the priority scriptCodeTherefore, you cannot use include to dynamically include ASP files. We can use the Execute function to dynamically execute the required code.
Method:
Execute (ASP code)
Example: (vbcrlf is a line break)Copy codeThe Code is as follows: Execute ("class clsabc" & vbcrlf & "public function output" & vbcrlf & "response. write 123 "& vbcrlf &" end function "& vbcrlf &" End Class ")Copy codeThe Code is as follows: dim objabc
Set objabc = new clsabc
Objabc. Output
Set objabc = nothing
ASP code can be read from a file or database before execution. Note that the executed code should not contain <% and %>
Be sure not to be confused with server. Execute. The server. Execute parameter is an ASP virtual path, and using this function not only does not dynamically declare the class, or even cannotProgramVariable value.
Example:
Main. asp Copy codeThe Code is as follows: dim strabc, objabc
Strabc = "test"
Server. Execute ("sub. asp ")
Response. Write strabc
Set objabc = new clsabc
Objabc. Output
Set objabc = nothing
Sub. asp Copy codeThe Code is as follows: strabc = "execute"
Class clsabc
Public Function output
Response. Write "class"
End Function
End Class
After main. asp is executed, only test is output, while objabc cannot be instantiated.