ASP Lecture 5: ASP Components (2)
Author:Eve Cole
Update Time:2009-05-30 19:58:12
In the previous lecture, we learned how to create components, using browser capability components, File Access components, AD Rotator components, and Content Linking components. We also learned about the CreateObject method, MapPath method, and HTMLEncode method of the Server object. This lecture will continue the study of components.
1. Email component: NTS Collaboration Data Objects
We often see on the Internet that many sites provide online sending functions (that is, using forms to implement Question submission, Support or information feedback, etc.) or send confirmation messages to visitors. This function is difficult to achieve for personal homepages because it requires additional support from the homepage provider (the online writing on my personal homepage is written in CGI and has nothing to do with ASP). Here is a simple example of its principle. example:
Special note: All examples given in this lecture are debugged on Windows NT4.0 Server+IIS (Internet Information Server) 4.0, but most of them are also applicable to Windows9.x+PWS. However, to learn how to use ASP well, it is best to install Windows NT to coexist with Windows 95/98 (don’t be afraid if you have not installed it before, it is very easy, as long as the machine is slightly better, NT can automatically become Win NT/Win9 after installation. x dual boot).
<% 'wuf30.asp
Dim Mail
'Create an Email component
Set Mail = Server.CreateObject("CDONTS.NewMail")
'Send Email
Mail.Send "[email protected]","[email protected]","Subject","Body"
Set Mail = Nothing
%>
This is the simplest example. In fact, using this component, you can send emails in plain text format or HTML hypertext format. The component also supports carbon copy (CC) and blind carbon copy (BCC), and can include images. and attachments, and can even receive emails. It should be said that the function is quite powerful. But I personally don't appreciate it very much, because to use this component, you must install the SMTP service of Windows NT Server and IIS4.0 (Microsoft style), and this component does not support the POP3 protocol. Therefore, if you cannot send emails normally using this component, you can open the Internet Server Manager to see if the Default SMTP Site has been started (Start) and some related settings. However, if you are a Microsoft fan, you can go to my homepage (http://wuf.bentium.net/) to download the routines wuf31.asp and sendmail.asp of this component and study it yourself.
2. Use third-party components So far, the components we have introduced are included in IIS4.0, and you can use these components directly. In addition, you can also obtain the following two components from the Microsoft IIS Resource Kit CD (or try your luck at http://www.microsoft.com/iis to see if they can be downloaded):
l Page Counter component: web page counter
l Permission Checker component: Web page access permission confirmation component
The introduction of the built-in components of IIS4.0 has come to an end here, but the study of ASP components still needs to continue. On the one hand, there are very few built-in components in IIS4.0, and on the other hand, the functions of these provided components may not be very powerful. , suitable for your needs. Therefore, a larger number of resources are hundreds of third-party components existing on the Internet. Some of them are free, some provide limited-function versions or evaluation versions, and of course more of them cost money (a component costs three digits of $, Have you made a mistake! It’s just a roundabout “blackmail”). Using these components can make you a pseudo-ASP expert, allowing you to quickly and easily create a powerful homepage. "The sigh. We might as well find this feeling through a few examples.
(1) File upload component AspSmartUpload (free)
Download the component first: The file size is about 100K (you can also download it from my site). After downloading and unpacking, there are more than thirty files in total, located in different directories. You can refer to the instruction files to study them yourself. Here is just a complete example to illustrate how to use third-party components.
Find the two files AspSmartUpload.dll and AspSmartUploadUtil.dll, and use the "regsvr32.exe aspsmartupload.dll" and "regsvr32.exe aspsmartuploadutil.dll" command lines respectively in the command prompt of the web server to register the component (if you are When using Regsvr32.exe for the first time, you can first copy these two DLL files to the "Winnt/System32" or "Windows/System" directory of the web server). If the registration is successful, the word "succeeded" will appear in the pop-up window. (Note: You must register before using third-party components. Some third-party components are installed and can be automatically registered, while more like this require manual registration by yourself). After successful registration, the next step is to write code to use the component. This example consists of two files (note that please do not use Chinese file names during testing):
wuf32.htm – Front-end web page (form) for uploading files
<HTML>
<style type="text/css">
<!--
input { font-family: "宋体", "Times New Roman"; font-size: 9pt; line-height: 16pt}
-->
</style>
<BODY BGCOLOR="white">
Web page for uploading files (you can define the number of files you can upload, but the file name cannot contain Chinese characters)
<HR>
<FORM METHOD="POST" ACTION="wuf34.asp" ENCTYPE="multipart/form-data">
<!-- TEXT -->
Username: <input TYPE="TEXT" name="myText" value=""><br>
<!-- PASSWORD -->
Password: <input TYPE="PASSWORD" name="myPASSWORD" value=""><br>
<!-- HIDDEN -->
<input TYPE="hidden" name="myHidden" value="hidden"><br>
<!-- File -->
File 1: <INPUT TYPE="FILE" NAME="FILE1" SIZE="50"><BR>
File 2: <INPUT TYPE="FILE" NAME="FILE2" SIZE="50"><BR>
File 3: <INPUT TYPE="FILE" NAME="FILE3" SIZE="50"><BR>
File 4: <INPUT TYPE="FILE" NAME="FILE4" SIZE="50"><BR>
<INPUT TYPE="SUBMIT" VALUE="Upload">
</FORM>
</BODY></HTML>
Press the "Upload" button, and the background is handled by the file wuf34.asp (you can also download the simpler wuf33.asp):
<HTML><BODY BGCOLOR="white">
File upload results:
<HR>
<%
Dim mySmartUpload, item, value, file
' First create the component as follows
Set mySmartUpload = Server.CreateObject("aspSmartUpload.SmartUpload")
mySmartUpload.Upload
' Use For Each loop to get the value of each item in the From form
For each item In mySmartUpload.Form
For each value In mySmartUpload.Form(item)
Response.Write(item & " = " & value & "<BR>")
Next
Next
Response.Write "<Hr>"
'Upload file data
' Response.Write("Number of files=" & mySmartUpload.Files.Count &"<BR>")
Response.Write("Total bytes = " & mySmartUpload.Files.TotalBytes &" bytes<Br><Br>")
Response.Write("File list: " & "<Br>")
' for each file - there is an easier way, see wuf33.asp
For each file In mySmartUpload.Files
If not file.IsMissing Then
'Save it under C:temp with the original file name
file.SaveAs("c:temp" & file.FileName)
Response.Write(file.FileName & " (" & file.Size & "bytes)<BR>")
End If
Next
Set mySmartUpload = Nothing
%>
</BODY>
</HTML>
For more detailed usage and functions of this component (such as limiting the type and size of uploaded files, uploading to the database, downloading files or database fields, etc.), you can read the samples or study the foreign help yourself. If you feel that reading E-text is too tiring, you can also download a nationally produced File Upload component, which has Chinese help and samples. It is still good. Download address:.
(2) Graphic component: Dundas Pie Chart (pie chart)
First listen to what the component provider says: "Flashing performance, high-quality graphics that can make people faint, powerful, high-speed, and incomparable flexibility." Wow, bragging is better than Wei Xiaobao. Isn't that the case? Let's look at the results. one:
With such a pie chart, you can also conduct surveys like Sina.com. What is so popular is free. What are you waiting for? Get on your slow cat and pull it down:
(1) 3DPieCSC.EXE: http://www.dundas.com/downloads/freeproducts/files/3DPieCSC.EXE
(2) FPDocInst.exe: http://www.dundas.com/downloads/freeproducts/files/FPDocInst.exe
This component is included in 3DPieCSC.EXE. The latter is a documentation and installation file. I installed it in the "C:Inetpub3dPieCSC" directory of the server. This component comes with two extremely complex sample programs. It shows its dazzling performance and is more difficult to understand. Here is a simple and practical popular example:
wuf36.htm, calling the ASP file through the <IMG> tag:
<HTML><BODY>
<IMG src="wuf37.asp">
</BODY></HTML>
wuf37.asp, used to generate graphics (same as above, please do not use Chinese in the code):
<%@ Language=VBScript %>
<% Option Explicit
Dim objPieChart
Set objPieChart = Server.CreateObject("Dundas.PieChartServer.1") 'Create the component first
'Set working directory
objPieChart.DirOutput = "C:Inetpub3dPieCSCSampleChart"
'Set the directory where the template file is located
objPieChart.DirTemplate = "C:Inetpub3dPieCSCSampleTemplates"
'Material catalog - you can easily change the material and color of graphics
objPieChart.DirTexture = "C:Inetpub3dPieCSCSampleTextures"
'Select a template file, which can be edited or modified by yourself
objPieChart.LoadTemplate "PieInTheSky.cuc"
'Graphic title
objPieChart.Title = "This is a Sample"
'Add various items, including weight label descriptions
objPieChart.AddData 40, "Item1:40%","China"
objPieChart.AddData 30, "Item2:30%","USA"
objPieChart.AddData 30, "Item3:30%","Other"
'The output result is a graphic, the width and height can be specified
objPieChart.SendJPEG 400,300
Set objPieChart = Nothing
%>
To be honest, this free thing is pretty good, but the routines it provides are too complex to be mastered at the drop of a hat. Now you may want to draw inferences from one example and understand how to get a histogram. There is indeed such a component: ShotGraph, but it doesn’t need to be so complicated. You only need to prepare a histogram picture (you can’t do it! See others There is it on the web page, just save it as a separate one), just use the HTML tags Weight and Height to stretch and compress it proportionally (<img src = bar.gif width = <%=variable%> height = 10>).
In addition, in order to make up for the responsibly brief beginning of this lecture, I hereby solemnly recommend two Email components:
(1) aspSmartMail:, be careful not to use Chinese in the code, otherwise you will not be able to send a letter. For details, see the routine wuf35.asp.
(2) W3 Jmail: http://download.dimac.net/jmail/jmail.exe.
(3) ChinaMail: http://wuf.bentium.net/, an all-Chinese Email component written by myself.
I personally have complicated and heavy feelings about components. There are indeed too few built-in components in IIS4.0, but many online E-text components do not support Chinese and are not fun to use. So why not use domestic components? Just go to http://www.chinaasp.com/, the best website in China, to find out. The listed components are very few, which is disappointing. Then there is only one way left, and that is to write it yourself (but can ordinary people write it by themselves? This is a doubt). I quite agree with ChinaASP's call. It probably means that no software company in China has publicly published ASP components. Although there are tons of books on ASP, they are not of high taste. Indeed, when I was invited to write this lecture, there were very few books on ASP on the market, but now, suddenly there are many. I still recommend that you buy books written by foreigners. Firstly, they are available on CD, and secondly, they are indeed imported products in general. It's better said, it reads like that, and it's not rigid.
Finally, I will provide you with several component resource sites:
(1) http://www.serverobjects.com/
(2) http://www.15seconds.com/
(3) http://www.activeserverpages.com/
(4) http://www.softartisans.com/