XML is used to define objects, methods, attributes, and so on using scripts and components written in Extensible Flag Language (XML) and. Xml.
The script also provides a function. Scripting languages can be JavaScript, VBScript, and so on. The use of the site's application procedures and the general example of the site, can now be converted into scriptlets. As long as you use scriptlets to write components, they can be reused in the Web site or use the various parts of the program, can be used on the server (such as ASP code) also can be used in the client (such as browser).
Here we will focus on the server-side scriptlets for component ASP code.
Earlier, ASP developers were accustomed to writing include files. Used to do public service-side routines,
Also used in their website application program. Functionally, include files are limited to simply referencing them in the page.
Completes the function of passing parameters.
The same common routines are now able to add scriptlet methods and help with the use of components in the application program.
This method is now widely used in the Web site application program, can be run on the same server application reuse.
This approach makes it very easy to get (Pull-down) data out of the database.
Example: Establish scriptlet methods and attributes that make it very popular to get data from a database.
And make all the applications running on the same server use the same scriptlet without having to write code again.
The code is as follows:
Scriptlet file name is SCP_QUERY2LIST.SCT
<! [CDATA] [
Sub query2list (objconn, query)
Dim objRS
Set objRS = objconn.execute (query)
If objrs.eof and Objrs.bof Then
Response.Write "<option value= ' None ' > No records found. </option> "
Else
Do as Not objrs.eof
Response.Write "<option value= '" & objRS (0) & "' >" & objRS (0) & "</option>"
Objrs.movenext
Loop
End If
Objrs.close
Set objRS = Nothing
End Sub
]]>
</script>
</scriptlet>
Specific descriptions of the various elements used in the scriptlets can be found at http://msdn.microsoft.com/scripting.
Here's how to specifically invoke Scriptlets code: (This code can be used as long as the scriptlets application is registered on the same server)
query2list.asp file:
<%@ Language=vbscript%>
<%
Option Explicit
Dim objconn
Dim DBPath
Dim SQL
Dim objscpquery2list
'---query required for pull down
sql = "Select Authorfirst from Papers"
Set objscpquery2list = Server.CreateObject ("Scpquery2list. Scriptlet ")
%>
<body>
<center>
<form name = "FR1" >
<select>
<option value= "None" selected> Select publisher </option>
<% Call Objscpquery2list.query2list (objconn, SQL)%>
</select>
</form>
</center>
</body>
<%
Objconn.close
Set objconn = Nothing
Set objscpquery2list = Nothing
%>
The problems that arise:
The first use of scriptlets is likely to be the problem, is the memory waste phenomenon, the improvement method is as follows:
The ASP object is passed to the scriptlets instead of using the ASP interface. (Just don't use <implements type= "ASP" id= "ASP"/> Affirm)
TESTSCP.SCT:
? XML version= "1.0"?>
<scriptlet>
<?scriptlet error= "true" debug= "true"?>
<registration
description= "TESTSCP"
Progid= "TESTSCP. Scriptlet "
version= "1.00"
Classid= "{78a33aa0-335d-11d3-a9a9-0080c8034244}"
>
</registration>
Function Get_cnnstate ()
Get_cnnstate = Cnnstate
End Function
Sub Aspconnect (oserver, oapplication, Osession, Orequest, Oresponse)
Set Server = oserver
Set application = oapplication
Set session = Osession
Set Request = orequest
Set Response = Oresponse
Cnnstate = True
End Sub
Sub Testwrite (SHTML)
Response.Write SHTML
End Sub
Sub Testwriteline (SHTML)
Response.Write SHTML & "<BR>"
End Sub
]]>
</script>
</scriptlet>
The ASP program that passes the ASP object is as follows:
Testscp.asp Code
<%
Set scrip=server.createobject ("TESTSCP. Scriptlet ")
If Err Then
Response.Write "<br>error:" & Err.Number
Response.Write "<BR>" & Err.Description
Response.Write "<BR>" & Err.Source
Response.End
End If
Response.Write "<BR> cnnstate=" & Scrip.cnnstate
If Err Then
Response.Write "<br>error:" & Err.Number
Response.Write "<BR>" & Err.Description
Response.Write "<BR>" & Err.Source
Response.End
End If
Response.Write "<br>connecting ..."
Scrip. Aspconnect Server, application, Session, Request, Response
If Err Then
Response.Write "<br>error" & Err.Number
Response.Write "<BR>" & Err.Description
Response.Write "<BR>" & Err.Source
Response.End
End If
Scrip. Testwriteline ""
Scrip. Testwrite "This is the"
Scrip. Testwrite "And this is the second."
Response.Write "<br>testing ... Writeline<br> "
Scrip. Testwriteline "This is text with a line break."
Scrip. Testwriteline "And so are this."
%>
The code above does not include the <implement type = "ASP"/>, but the ASP object can still be accessed.
Because they are passed to scriptlet as objects.
The following is a very common time to take the Beaver Son:
<! [CDATA] [
Sub option_num (num)
For i = 1 to num
If i<10 Then
x = 0 & I
Else
x = i
End If
Response.Write "<option value =" & X & ">" & X & "</option>"
Next
End Sub
Sub Option_month ()
For i = 1 to 12
If i<10 Then
x = 0 & I
Else
x = i
End If
Response.Write "<option value =" & X & ">" & MonthName (x,true) & "</option>"
Next
End Sub
Sub Option_year ()
For i =-1 to 3
yy = Year (DATEADD ("yyyy", I,date ()))
Response.Write "<option value =" & yy & ">" & yy & "</option>"
Next
End Sub
</body>
Keep in mind that all programs on the server are now able to use this scriptlet, which can reduce the use of include files.
The above code can also add features, such as displaying dates in different formats.
That is to say, if an application needs to display the DD-MM-YYYY date format, it can call its own function in Scriptlet.
Finally, one of the benefits of using scriptlet is that it's not like a real ASP component, because the real ASP component is registering and canceling the
You need to restart IIS, and using Scriptlet is not necessary, just a few lines of code.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.