微软提供的功能强大的ASP-HTML转换工具.它将常用的ASP脚本转换为HTML从而减轻服务器的负担language. VBScript and JScript?are the two usual options, but provided you have a compliant parser, any scripting language is fine. Francesco Balena covered the ScriptControl in detail in the July 1999 issue of MIND (see "Exploring the Microsoft Script Control"). Tobias Martinsson's article, "Active Scripting with PerlScript," in the August 1999 issue of MIND, explores the use of Perl with ASP. When it comes to using the ScriptControl you need to do three things: set up the language, add as many objects as you want to the script namespace, and execute the script code. In my special edition browser, I set the language to VBScript during the form load event. At the same time, I create instances of all the objects I want to be visible to the script engine at runtime. Named items visible to the parser at runtime is a concept that warrants further explanation. The whole set of named items forms the script's namespace. A Windows Script parser (such as the Microsoft parser for VBScript) receives a vocabulary of known names at startup. This dictionary contains the language's keywords and global resources such as variables, objects, and subroutines. Behind each name (such as MsgBox) there's a programmable entity—whether it is a parser-specific function or the method of a certain in-process COM object. You can add new names to this namespace. Better yet, the interface of the ScriptControl (and thereby the Windows Script programming interface) allows you to do this in a very handy way. Look at the following code snippet: Set m_objResponse = CreateObject("MyASP.Response") m_objScriptCtl.AddObject "Response", m_objResponse Through the AddObject method, the ScriptControl adds a named item called Response to the script namespace. From then on, it is considered a language item. Each call to this element is automatically routed to the COM object you specified as the second argument of AddObject. Those two lines are part of the CAspParser.Initialize method and m_objScriptCtl is the instance of the ScriptControl that is going to be used for script processing. Once you execute those lines, any script code you run through that instance of the ScriptControl recognizes Response as a keyword and uses MyASP.Response to work with it. It's a very common technique in scripting. Incidentally, this is the same technique that allows IIS to inject the true ASP object model in the scripting context of a server-side ASP page. This workaround also makes it possible for Windows Script Host (WSH) scripts to rely on a system-provided WScript object. Call in Action When the browser's main form is ready to parse and display the ASP code, it calls the ParseTextToFile method, which takes two file names: the source ASP file and the target HTML file. When the method returns successfully, the form simply navigates to the newly created local HTML page. The full source code of the CAspParser class is shown in Figure 4. Let's see how it works step by step on a very simple ASP page: <html> <body> <% X=1 %> <% Response.Write "Hello, world!" %> <hr> The value of X is <%= X%> </body> </html> The CAspParser class initializes the script control by setting the script language to VBScript (this is not strictly necessary since the ScriptControl already defaults to it), and adding a brand new instance of the MyASP.Response object to the namespace. The control then passes to the method ParseTextToFile. It receives the name of the ASP file, verifies it has an ASP extension, and reads in all of its content. I used the Scripting.FileSystemObject for clarity only (see Figure 4). Using the CreateFile API or other I/O technique could give you better performance. The string with all the ASP content is then parsed for <%…%> blocks. All the text outside of these markers is written to the Response object. It accumulates the text into an internal string buffer that emulates the stream where the real ASP Response object writes. In this way, the simulated Response object caches all the output, just as the real ASP Response does when buffering is on. Note that under IIS 5.0 buffering is on by default, while it was turned off by default in earlier versions of IIS. In Figure 4, the Response.Clear method is used to clear any buffered text that you accumulated through repeated calls to Response.Write. This Clear method plays exactly the same role it does in the real ASP object model you're used to on the server. Now let's have a closer look at the implementation of the simulated ASP Response object. To further illustrate the language neutrality of COM and to avoid the problem of writing objects in Visual Basic with the same method names as some language keywords (such as Write or End), I decided to write the MyASP 上一篇:StoredProcedure在企业网站开发中的应用(1) 下一篇:动态网页技术--CGI:ASP:JSP:PHP(1) 更多相关文章
|
推荐文章
精彩文章
|