Linux中国 Linux中国门户站!
设为主页 设为主页
收藏本站 收藏本站
 
当前位置 :首页 ->编程语言 ->ASP ->正文

微软提供的功能强大的ASP-HTML转换工具.它将常用的ASP脚本转换为HTML从而减轻服务器的负担

来源:Linuxdby.com 作者:Webmaster 时间:2007-06-01 点击: [收藏] [投稿]

objects using ATL and Visual C++? The implementation of the MyASP.Response object is straightforward (see
Figure 5). The MyASP objects need to expose methods with signatures that match the way you're using them
in your client-side ASP pages. If you're using the client-side ASP engine to work on specific client-only
pages, then there's no particular reason for you to use a custom object that mimics the ASP's Response.
You are better off writing a completely custom object with the programming interface you prefer. The need
to mimic the signatures of ASP intrinsic objects arises when you're writing dual pages to be used on the
Web as well as locally on a CD.
When you invoke the Write method on MyASP.Response, the text you pass in is added to an internal member
variable that'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, there's no need to make the
internal buffer available to the scripts in the ASP page. In fact, the ASP Response object doesn't have a
method or property (such as ResponseBuffer) that returns the text accumulated in the internal buffer. In
this client-side 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 MyASP.Response object is similar—but not identical to—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 server-side editions of Response requires.
In Figure 6 you can see that both the custom browser and Internet Explorer render my simple page in the
same way. If you open Explorer in the folder that contains the specified ASP page and double-click 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 double-click 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 client-side parser doesn't support.

Figure 6 The Custom Browser versus Internet Explorer  

Consider a page like the following, which is nearly identical to the previous one except for a
Response.End statement. <html>
<body>
<% x=1 %>
<% Response.Write "Hello, world!" %>
<hr>
<% Response.End %>
The value of X is <%= x%>
</body>
</html>


Figure 7 shows that the End method correctly stops the processing. If you're confused by the truncated
output in the HTML textbox, don't be too concerned. Try viewing the same document through Internet
Explorer and HTTP and you'll see that the HTML the browser receives from the Web server is exactly the
same.

Figure 7 Using Response.End  


A possible stumbling block in the conversion process is the meaning of the = sign which is often used
within <%...%> code blocks to denote Response.Write. In fact, The value of X is <%= x%>


is exactly the same as The value of X is <% Response.Write x %>


To deal with this particular situation (and other similar circumstances) I've added the ResolveAmbiguity
method to the CAspParser class. Each time that the script command begins with "=" it replaces the
character with a Response.Write.



A More Complicated Page
So far I've worked with a very simple ASP page. Let's use the client-side parser to work with a more
complex ASP page that involves databases. Figure 8 shows an ASP page that fills and displays a table with
a few records taken from an OLE DB data source. Despite the use of ActiveX Data Objects (ADO), the
structure of the page is relatively simple. To make this example more realistic I would need to implement
the Request object and the simulation of the POST and the GET HTTP commands. I'll cover those topics next
month.

Figure 9 The Page Rendered in Internet Explorer  

In Figure 9 you can see how Internet Explorer renders this page. Figure 10 shows that the offline parser
renders it the same way.

Figure 10 The Page Rendered in the ASP Browser  

 如果您对本文有任何疑问或者建议,请到讨论区发表您的意见: >> 论坛入口 <<



上一篇:StoredProcedure在企业网站开发中的应用(1)   下一篇:动态网页技术--CGI:ASP:JSP:PHP(1)

文章评论】 【收藏本文】 【推荐好友】 【打印本文】 【我要投稿】 【论坛讨论
更多相关文章
Power by linux-cn.com 粤ICP备05006655号