计算机专业文献翻译--功能强大的asp-html转换工具-jsp程序(编辑修改稿)内容摘要:

at instance of the scriptControl recognizes Response as a keyword and uses to work with it. It39。 s a very mon 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 serverside ASP page. This workaround also makes it possible for Windows script Host (WSH) scripts to rely on a systemprovided Wscript object. Call in Action When the browser39。 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. Let39。 s see how it works step by step on a very simple ASP page: html body % X=1 % % 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 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 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 %161。 % 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 buffering is on by default, while it was turned off by default in earlier versions of IIS. In Figure 4, the method is used to clear any buffered text that you accumulated through repeated calls to . This Clear method plays exactly the same role it does in the real ASP object model you39。 re used to on the server. Now let39。 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 objects using ATL and Visual C++? The implementation of the object is straightforward (see Figure 5). The MyASP objects need to expose methods with signatures that match the way you39。 re using them in your clientside ASP pages. If you39。 re using the clientside ASP engine to work on specific clientonly pages, then there39。 s no particular reason for you to use a custom object that mimics the ASP39。 s Response. You are better off writing a pletely custom object with the programming interface you prefer. The need to mimic the signatures of ASP intrinsic objects arises when you39。 re writing dual pages to be used on the Web as well as locally on a CD. When you invoke the Write method on , the text you pass in is added to an internal member variable that39。 s ready for return to the caller. This behavior mimics exactly what the ASP Response object does internally when buffering is on. The Clear method empties the buffer. MyASP also implements a property called ResponseBuffer that returns the current content of the output buffer. This property works in much the same way as the ASP Flush method. Each time you read it, its contents are cleared. IIS itself manages to send the transformed text to the browser via HTTP. Consequently, there39。 s no need to make the internal buffer available to the scripts in the ASP page. In fact, the ASP Response object doesn39。 t have a method or property (such as ResponseBuffer) that returns the text accumulated in the internal buffer. In this clientside emulation, the browser needs to get the transformed text from the object, and a property is more helpful than a subroutine like Flush. Finally, the End method sets an internal variable to false. This variable is exposed through the CanContinue property and is used to stop the loop that governs the parsing of the ASP text. As you can see, the programming interface of the object is similar161。 170。 but not identical to161。 170。 the ASP Response object. The logic behind the two objects is shared to some extent, but it clearly differs as the working context of the client and serverside editions of Response requires. In Figure 6 you can see that both the custom browser and Inter Explorer render my simple page in the same way. If you open Explorer in the folder that contains the specified ASP page and doubleclick the item, in most cases Visual InterDev?will open because it is the program that is usually registered to edit ASP files. If you want to be able to doubleclick on ASP files and see their content, you could associate them with a program like Visual InterDev. However, remember that a generic ASP page might be using objects like Session or Application that the clientside parser doesn39。 t support. Figure 6 The Custom Browser versus Inter Explorer?? Consider a page like the following, which is nearly identical to the previous one except for a statement. html body % x=1 % % Hello, world! % hr % % The value of X is %= x% /body /html Figure 7 shows that the End method correctly stops the processing. If you39。 re confused by the truncated output in the HTML textbox, don39。 t be too concerned. Try viewing the same document through Inter Explorer and HTTP and you39。 ll see that the HTML the browser receives from the Web server is exactly the。
阅读剩余 0%
本站所有文章资讯、展示的图片素材等内容均为注册用户上传(部分报媒/平媒内容转载自网络合作媒体),仅供学习参考。 用户通过本站上传、发布的任何内容的知识产权归属用户或原始著作权人所有。如有侵犯您的版权,请联系我们反馈本站将在三个工作日内改正。