Big Wolf's ASP + JavaScript Toolbox

xiaoxiao2021-03-06  60

Finally realized the wish (51 days) of the two months of 9CBS. I have issued an ASP development toolbox (more contributed to ASP and JavaScript) I believe that there is a big help to beginners, and even less questions :) ------------- ---------------------------------- Mail: cdonts: ----------- ---------------- <% set cdomail = server.createObject ("cdonts.newmail") 'Establishing a mail object cdomail.subject = "mail subject" "mail title cdomail.from = "Sender's mail" 'sender's address cdomail.to = "email will from"' recipient's address cdomail.body = "mail body" message content cdomail.send 'execution send%> This method sends mail It is the easiest, and it also brings a certain issue, that is, very few servers will open this service! We write procedures, in general, it is to say to code modularization, so convenient maintenance, it is also convenient to transplant.

So I am here to write this email into a subsidy. When you call it, you can call it directly (of course, if you are happy to write a function, you can see personal interest): <% 'parameter description' Subject : Mail title 'mailaddress: Address server address, such as SMTP.163.com' Email: Recipient Email Address' Sender: Sender Name 'Content: Mail content' FROMER: Sender Mail Address --- ------------------------- Jmail: Sub SendAction (Subject, Maildress, Email, Sender, Content, FROMER) Set Jmail = Server.createObject (" Jmail.smtpmail ") 'Create a Jmail object jmail.silent = true' jmail does not throw exception error, the return value is false and true jmail.logging = true 'Enable log jmail.charset =" GB2312 "mail text The code is the format of the Simplified Chinese Jmail.conteTtype = "text / html" 'email to HTML Jmail.Serveraddress = mailaddress' Send Mail Server Jmail.AddRecipient Email 'Mail Jmail.SenderName = sender' Mail Manager Name jmail.sender = FROMER 'Mail sender's email address jmail.Priority = 1' email emergency, 1 is the fastest, 5 is the slowest, 3 for the default jmail.subject = Subject 'message title Jmail. Body = Content 'The content' Since it is not used to copy, this two sentences are blocked here. If you need it, you can restore the address of 'Jmail.AddRecipientBCC Email' Pixabay Address' JMail. AddRecipientCC Email 'Email' s Address Jmail.execute () 'Executive Mail Send Jmail.Close' Examples of End Sub 'Calling this SUB DIM STRSUBJECT, STRMAIL, STRMAILADRESS , strsnder, strcontent, strfromer strsubject = "This is a test mail" strcontent = "Jmail component sent by Jmail! "StrEmail =" runbing@eyou.com "strFromer =" runbing@eyou.com "strMailAddress =" mail.ubbcn.com "Call SendAction (strSubject, strMailaddress, strEmail, strSender, strContent, strFromer)%> <% Set jmail = Server.createObject ("jmail.smtpmail") 'Creates a Jmail object jmail.silent =

True 'Jmail does not throw exception errors, returned to true jmail.logging = true' Enables log jmail.charset = "gb2312" mail text code as Simplified Chinese Jmail.conteType = "text / html" 'The format of the mail is HTML Jmail.Serveradraddress = "Server address"' Sending a message of the server jmail.addrecipient email 'mail Jmail.SenderName = "sendername"' mail sender's name Jmail.Sender = "Email Address "'Email the email address jmail.priority = 1' email emergency, 1 is the fastest, 5 is the slowest, 3 is the default value jmail.subject =" mail subject "The title jmail.body =" Mail Body "'mail content jmail.addrecipientBCC Email' Pixabay address jmail.addRecipientc Email 'mail CcCute ()' Upon to send Jmail.Close 'Close Mail Object%> W3 Jmail4. 3 The component redesides its internal structure - use the Message object instead of the original single object Jmail.smtpmail Send mail, some methods require authentication (such as 163, yahoo et al), can solve the following method: <% set jmail = Server.createObject ("Jmail.Message") 'Establishing an object Jmail.silent = true' mask error, return false with true two-value J mail.logging = true 'enables mail log jmail.charset = "gb2312" The text code of the mail is the national standard jmail.contenttype = "text / html" mail format is HTML format jmail.addrecipient email 'mail recipient's address jmail.from = "email from for sender" sender's E- Mail address jmail.mailserveruserName = "UserName The user name Jmail.mailServerPassword Jmail.mailServerPassword = "password of email" required by logging in to the mail server, the password required by logging in to the mail server Jmail.Subject = "mail subject" "Mail.body =" mail body " The content of the message jmail.prority = 1 'email emergency, 1 is the fastest, 5 is the slowest, 3 is the default value Jmail.send ("Server Address")' Executing Mail Send (via the Mail Server Address) Jmail.Close () 'Close Object%>

-------------------------------------------------- -------------- ASP's error collection (this depends carefully): ActiveServerPages, ASP0126 (0x80004005) -> Can't find file MicrosoftBProviderforoDbcDrivers (0x80040e21) -> SQL statement Error (Data Type Mismatch or Table Name (Field Name) error or table is in editing status, or table does not exist in CONN-open database) MicrosoftoledbProviderforoDBCDRIVERS (0x80040e14) -> SQL statement error (field name error, or data type match) MicrosoftOLEDBProviderforODBCDrivers (0x80040E07) -> sql statement error (type of variable data type to be inserted or updated in the field does not match) MicrosoftOLEDBProviderforODBCDrivers (0x80040E57) -> sql statement error (to be inserted or updated data overflow) MicrosoftOLEDBProviderforODBCDrivers (0x80040E10 ) -> SQL statement error (Update field name or data type error to update) MicrosoftoledbProviderforoDBCDRIVERS (0x80004005) -> SQL statement error (value to insert or update) MicrosoftoledbProviderforoDBcDrivers (0x80004005) -> Open the database error, not in the specified directory discovery database MicrosoftoledbProviderforodbcdrivers (0x80040E37) -> No table MicrosoftVbscript runtime error (0x800A000D) -> Error reference RS variable (RS object Close or undefined) MicrosoftVbscript runtime error (0x800A01C2 ) -> VBScript script error (VBScript statement error) MicrosoftVbscript runtime error (0x800A0006) -> VBScript script error (overflow error) MicrosoftVbscript compiler error (0x800A040E) -> Lack of Loop MicrosoftVbscript compiler error Mode (0x800A03EA) -> Miss if or Endif MicrosoftVbscript compiler error (0x800A03EE) -> The statement is not over (missing ")") MicrosoftVbscript compiler error (0x800A03F6) -> IF statement error (missing Endif) MicrosoftVbscript runtime Error (0x800A005B) -> Missing SET MicrosoftVbscript runtime error (0x800A0005) -> Variable Undefined MicrosoftVbscript Compiler Error (0x800A03F9) -> IF statement missing the THEN MicrosoftVbscript compiler error (0x800A0411) -> DIM statement definition error MicrosoftVbscript compiler error (0x800A0408) -> SQL statement error AdoDb.recordset (0x800A0BB9) -> SQL statement error (error statement or CONN statement does not define or error when assigning an RS property) AdoDB.Recordset (0x800A0cc1) -> RS object error (RS object itself does not exist or incorrectly quote a field name) AdoDb.Recordset (0x800A0BCD) -> RS object error (not recorded in the record set but operate on record set ) AdoDb.recordset (0x800a0e78) ->

RS object error (record set does not exist, lack rs.open statement) adoDb.recordset (0x800A0cc1) -> RS object error (reference to a field name that does not exist) AdoDb.Recordset (0x800A0E7D) -> conn definition Error AdoDB.Recordset (0x800A0CB3) -> Database Open in read-only mode, 20 very useful examples in data ASP programming 1. How to use ASP to judge your website's virtual physical path: Using MAPPATH Method

the physical path to this virtual website is: <% = server.mappath (" / ")%> 2. How do I know the user's browser? A: a method using the Request object strBrowser = Request.ServerVariables ( "HTTP_USER_AGENT") If Instr (strBrowser, "MSIE") <> 0 Then Response.redirect ( "ForMSIEOnly.htm") Else Response.redirect ( "ForAll.htm" End IF 3. How to calculate the average number of repetitive visits daily Answer: Solution <% StartDate = Datediff ("D", Now, "01/01/1990") if strdate <0 Then StartDate = startdate * -1 avgvpd = INT (Usercnt) / StartDate)%> Display result <% response.write (avgvpd)%> That is it.this page has referenced number november 10,1998 4. How to display random image <% DIM P, PPIC, DPIC PPIC = 12 Randomize P = INT (PPIC * RND) 1) DPIC = "Graphix / Randompics /" & P & ". GIF"%> Show > Preivous Page or with images such as:  < % = Request.ServerVariables (> 6. How to determine the other party's IP address answer: <% = Request.serverVariables ("remote_addr)%>

7. How to link to a pair of pictures: <% @ languages ​​= VBS cript%> <% response.expires = 0 strimagename = "graphix / errors / errooriamge.gif" response.redirect (strimagename)%> 8. Forcing Enter the password dialog: Take this sentence to the beginning of the page <% response.status = "401 not authorized" response.end%> 9. How to transfer variables from one page to another: Use the Hidden type to pass Variable <% form method = "post" action = "mynextpage.asp"> <% for each item in request.form%> <% s cript language = 'javas cript'> Alert ("<% = Yourvar%>") 11. Is there a way to protect your source code, do not give people an answer: You can download a Microsoft's Windows S Cript Encoder, which can be performed on the ASP script and client Java CRIPT / VBS CRIPT script. encryption. . . However, after the client encrypts, only IE5 can execute, after the server-side script is encrypted, only the S Cript Engine 5 installed on the server can be executed. 12. How can I send Query String from an ASP file to another? A: The former file adds the following sentence: response.redirect ("second.asp?") 13.Global.asa file always does not work? A: Only the web directory is set to Web Application, Global.asa is only valid, and Global.asa is valid in the root directory of a web application.

IIS4 can use Internet Service Manager to set Application Setting how to make the HTM file like an ASP file can execute script code? 14. How can I make the script code as the HTM file like an ASP file? Answer: Internet sevices manager -> Select Default Web Site -> Right Mark -> Menu Properties -> Home -> Application Setting -> Click button "Configuration" -> App Mapping -> Click button "Add "-> EXECUTABLE BROWSE Selection / Winnt/System32/INetsrv/asp.dll Extension Enter HTM Method Exclusions Enter Put.delete All OK. But it is worth noting that this is also processed by ASP.DLL for HTM, and the efficiency will be reduced. 15. How to register the component A: There are two ways. The first method: Hand-registered DLL This method is used from IIS 3.0 to IIS 4.0 and other web server. It requires you to execute in the command line mode, enter the directory containing the DLL, and enter: regsvr32 component_name.dll, for example C: / temp / regsvr32 aspemail.dll, will register DLL's specific information in the registry in the registry in the server . This component can then be used on the server, but this method has a defect. When the component is registered with this method, the component must have the corresponding setting NT anonymous account with permission to execute this DLL. In particular, some components need to read the registry, so the method of this registration component is only used in the case where there is no MTS on the server. Use: regsvr32 / u aspobject.dll Example C: / Temp / Regsvr32 The second method of using the MTS (Microsoft Transaction Server) MTS is IIS 4, but it provides a huge improvement. MTS allows you to specify that only privileged users can access components and greatly improve the security settings on the website server. The steps to register the components on the MTS are as follows: 1) Open the IIS Management Console. 2) Expand Transaction Server, right-click "PKGS Installed" and select "New Package". 3) Click Create An Empty Package. 4) Naming the package. 5) Specify an account or use "Interactive" (if the server is often used by login). 6) Now use Right-click "Components" after the package you just created. Select "New Ten Component". 7) Select "Install New Component". 8) Locate your .dll file and select Next to complete. To delete this object, just select its icon, then select Delete. Note: Pay special attention to the second method, it is used to debug the best way to write components, without having to restart the machine each time.

16. ASP and Access Database Connection: <% @ Language = VBS CRIPT%> <% DIM CONN, MDBFILE MDBFILE = Server.mappath ("Database Name. MDB") Set Conn = Server.createObject ("AdoDb.Connection" Conn .open "driver = {Microsoft Access Driver (* .mdb)}; uid =; pwd = database password; DBQ =" & mdbfile%> 17. ASP and SQL database connection: <% @ language = VBS cript%> <% DIM Conn set conn = server.createObject ("AdoDb.Connection") Con -.open "provider = SQLOLEDB; DATA SOURCE = SQL server name or IP address; UID = sa; pwd = database password; Database = Database Name%> Establishment record set Object: SET RS = Server.createObject ("AdoDb.Recordset") RS.Open SQL statement, conn, 3, 2 18. SQL common command usage: (1) Data Record Filter: SQL = "SELECT * FROM Data Sheet WHERE Field name = field value ORDER BY field name [DESC] "SQL =" SELECT * FROM DATA WHERE Field Name "SQL =" SELECT TOP 10 * FROM Data Sheet WHERE Field Name Order By Field Name [DESC] "SQL =" SELECT * FROM DATA WHERE Field Name in ('value 1', 'value 2', 'value 3') "SQL =" SELECT * FROM Datasheet WHERE field name BETWEEN Value 1 and Value 2 "(2) Update Data Record: SQL =" Update Datasheet Set Field Name = Field Value Where Condition Expression "SQL =" Update Data Table SET Field 1 = Value 1, Field 2 = Value 2 ... ... Field N = Value N Where Condition Expression "(3) Delete Data Record: SQL =" Delete from Data Sheet WHERE Condition Expression "SQL =" delete from Data table (delete data tables) (4) Add data record: SQL = "INSERT INTO data table (field 1, field 2, field 3 ...) value (value 1, value 2, value 3 ...)" SQL = "INSERT INTO Target Data Table Select * FROM Source Data Sheet" (Add Source Data Sheet Record to Target Data) (5) Data Recording Statistics: AVG (Field Name) Licensed a table bar average value count (* | Field Name) Statistics on the number of data lines or the value of the value of the value of a value of a certain column get the maximum value min (field name) get the smallest value Sum (field name) in a table bar. ) Adding the value of the data bar to the above function: SQL = "SELECT SUM (Field Name) AS alias from Datasheet WHERE Condition Expression

SET RS = conn.excute (SQL) uses RS ("alias" to get the value, and other functions are used. (5) Establishment and deletion of data sheet: CREATE TABLE DATA Name (Field 1 Type 1 (Length), Field 2 Type 2 (Length) ...) Example: Create Table Tab01 (Name Varchar (50), DateTime Default NOW )) DROP TABLE Dataset Name (Permanent Delete A Data Table) 19. Method of Recording Set Objects: rs.Movenext Moves the Record Pointer from the current location RS.MOVEPREVIOUS to move the record pointer up from the current location Rs.Movefirst Move the record pointer to the data table RE. RS.MOVELAST Move the record pointer to the last line RS.AbsolutePosition = N Move the record pointer to the data table Nth line rs.absolutepage = N Move the record pointer to move the record pointer The first line of the nth page RS.PageSize = N Sets each page for n-record RS.PageCount Returns the total number of pages based on PageSize Rs.Recordcount Returns the total number RS.BOF Returns the record pointer over the data sheet header, TRUE Indicates whether false is rs.eo returns the record pointer over the end of the data table, the true representation is whether false deletes the current record, but the record pointer does not move the RS.AddNew to the data table end RS .Update update data table record -------------------------------------- 20 RecordSet object method Open Method RecordSet.open Source, ActiveConnection, Cursortype, LockType, Options Source RecordSet objects can connect the Command object via the Source property. The Source parameter can be a COMMAND object name, a SQL command, a specified data table name or a Stored ProCedure. If this parameter is omitted, the system uses the Source property of the Recordset object. ActiveConnection RecordSet objects can connect the Connection object through the ActiveConnection property. The ActiveConnection here can be a connection object or a string parameter containing database configuration (ConnectionsTRING).

CURSORTYPE RECORDSET Object Open method The CURSORTYPE parameter represents what kind of cursor type starts data, including AdopenForwardOnly, AdoPENDYNAMIC, and AdoPenStatic, is described below: ---------------------------------------------------------------------------------------------------------------------- ------------------------------------------- constant constant value description - -------------------------------------------------- --------- AdopenForwardonly 0 default, start a cacope that can only move forward. AdopenKeyset 1 Start a KEYSET type cursor. AdoPendynamic 2 launches a dynamic type cursor. AdoPenStatic 3 launches a cursor for a Static type. -------------------------------------------------- ----------- The above cursor type will directly affect all the properties and methods all of the Recordset object, the following list describes the differences between them.

-------------------------------------------------- ----------- RECORDSET Property AdopenForwardonly AdopenKeyset AdoPENDYNAMIC ADOPENSTATIC --------------------------------- ---------------------------- AbsolutePage does not support you do not support readable write readable write absolutePosition does not support readable write ActiveConnection readable and writable readable write readable write-readable and write-only bookmark does not support you read / write Cachesize readable and write Cachesize Ready-write read-read-read-read-read-read-read-read-read-read-read-read-only read-read-read-read-read-read-read-read-read-read-read-only-read-read-only-read-read-read-like read-read-only-read-read-only-read-read-only-read-read-only-read-read-only-read-read-only-minded write LockType can read and write can read and write can read and write can read and write can read and write MarshalOptions can read and write can read and write can read and write can read and write MaxRecords can read and write can read and write can read and write can read and write PageCount only not supported not supported read-only read PageSize can read and write can read and write can read and write can read and write RecordCount not supported not supported read only read-only Source can read and write can read and write can read and write can read and write State read-only read-only read-only read-only read-only read-only Status Read-only AddNew support support support support CancelBatch support support support CancelupDate support support support CLONE does not support unsupported support support support support support support support support support support GETROWS support support support MOVE does not support support support MOVEFIRST support support support MoveLAST does not support support support MOVENEXT support support support MOVEPREVIOUS does not support support support NEXTRECORDSET Support Support Open Support Support Support REQUERY Support Support Support Supporting RESYNC does not support support support support support Support support support support UPDATE support support support support UPDATEBATCH Support support support -------------------------- ---------------------------------- in which the nextRecordset method does not apply to the Microsoft Access database. The LockType parameter of the LockType RecordSet object Open method indicates the Lock type to be used. If this parameter is ignored, the system will be preset with the LockType property of the Recordset object. The LockType parameter contains AdlockReadonly, AdlockPrsSIMistic, AdlockOptimistic, and AdlockBatchOptimistic, etc., is described below: ------------------------------------------------------------------------------------------------------------------------------------ -------------------------- constant constant value description ------------------- ------------------------------------------ AdlockReadOnly 1 default value, Recordset Objects are launched in read-only way, and how to operate AddNew, Update, and Delete. AdlockPrsSIMistic 2 when the data source is being updated, the system is temporarily locked to maintain data consistency.

AdlockOptimistic 3 When the data source is being updated, the system does not lock the action of other users, and other users can increase, delete, and change the data. AdlockBatchOptimistic 4 When the data source is being updated, other users must change the CURSORLOCATION property to ADUDECLIENTBATCH to increase, delete, and change the data. Online Player: 1), RM file Online Play Autostart = "false" When you open the page, Autostart = "True" When you open the page, you will listen to the sound height = 25 width = 50 has a different value, and the player panel is somewhat different. 2), MIDI, AU, AVI file online play

AutoStart = "false" is on a time, autostart = "true" opens the page, listening to the sound height = 25 width = 50 has a different value, the player panel is somewhat different 3), ASF file online play

among them

0 To open the page in standby, open the page directly to play directly

Change NT Password: <% Sub ChangeUserPassword (Computer, UserName, oldPassword, newPassword) Dim adsUser, foundErr, ErrMsg On Error Resume Next foundErr = False ErrMsg = "" Set adsUser = GetObject ( "WinNT: //" Computer "/ " UserName ", user ") If Err.Number <> 0 Then foundErr = True ErrMsg =" User not found! "response.write err.description Else adsUser.ChangePassword oldPassword, newPassword adsUser.SetInfo response.write err.description &" 2 "if Err.Number <> 0 Then Founderr = true errmsg = now &". Error Code: "& HEX (Err) &" - ​​"& Err.Description &"

"Err.clear end if end if response.write founderr if not founderr the objcontext.setcomplete response.write"

The password has been successfully modified! "Response.write" "else objcontext.seTabort response.write"

The wrong old password, please re-enter the correct old password! "& Errmsg response.write" "end if set adsuser = Nothing End Sub Response.write"

Change NT user password

"Computer =" abc "username =" ccc "oldpassword =" c "newpassword =" csl "ChangeUserPassword Computer, UserName, Oldpassword, NewPassword%> How to use ASP to import SQL Server's table to Access: <% set conn = server .CreateObject ("adoDb.connection") conn.open "driver = {SQL Server}; server = mamaco; uid = Linner; PWD = 123; DAT abase = Linner" SQL = "Select * from scjh" set = conn. Execute (SQL)%> <% SET Conn1 = Server.createObject ("AdoDb.Connection") param = "driver = {Microsoft Access Driver (* .mdb)}" Conn.open param & "; DBQ =" & Server. MAPPATH ("scjh.mdb") Conn1.execute ("delete from scjh")%> <% do while not rs.eof%> <% DIM KTDH, SCPH, SCTS, JHQTSJ, YHXDSJ, YXJ, RWBH KTDH = RS ( "KTDH") SCPH = RS ("SCPH") SCTS = RS ("SCTS") JHQTSJ = RS ("JHQTSJ") YHXDSJ = RS ("YHXDSJ") YXJ = RS ("Yxj") RWBH = RS ("RWBH) ")%> <% sql1 =" INTO SCJH (KTDH, SCPH, SCTS, JHQTSJ, YHXDSJ, YXJ, RWBH) VALUES ('"& KTDH &",' "& SCPH &", "& SCTS &" , '"& jhxdsj &",' "& yhxdsj &", "& yxj &", "& rwbh &") "conn1.execute (sql1)%> <% rs.movenext loop conn1.close conn.close%> <% Response.Redirect "/ Download / Scjh .mdb "%> The following is JS: collecting Meiz (plum snow): ----------------------------- --------- 1. οncοntextMenu = "Window.Event.ReturnValue = false" will completely shield the mouse button

NO can be used for Table 2. Uncheck, prevent copy 3. οnpaste = "return false" is not allowed to paste 4. οNCοPY = "Return False;" oncut = "Return False;" Prevent Copy 5. Rel = "Shortcut icon" href = "Favicon.ico"> IE addressed to your own icon 6. rel = "bookmark" href = "favicon.ico"> You can display your icon in your favorites 7. Turn off the input method 8. Always bring Frame