Recommended: Use ASP to create in-site search If you have a huge website and lots of content, it is often difficult for visitors to find what they need. At this time, you need a website search to help visitors find the information they are looking for faster! Now you can easily implement this function with asp, not to mention that there are so many sites that support asp now. You can use this search engine to search any of your homepage
<%@ Language=VBScript %>
<%
Option Explicit
Dim strSubmit 'Form used to save the value of the submit button
Dim strPRinterPath 'Save the value of the network printer path in Form
Dim strUsername 'Value of username in Form
Dim strPassWord 'The value of password in Form
Dim strMessage 'Form prints the value of the content
Dim objFS 'File System Objects in VBScript
Dim objWSHNet 'Net Network Objects in WSH
Dim objPrinter 'Print object
strSubmit = Request.Form(Submit)
%>
<HTML>
<HEAD>
<META NAME=GENERATOR Content=Microsoft Visual Studio 6.0>
</HEAD>
<BODY>
<%
If strSubmit = Then
%>
Note that:
Since this is a demonstration, the account and password about NT are passed in the asp using unencrypted means.
The login process should be handled safely in real use.
<FORM action=ASPPrint.asp method=POST id=form name=form>
<TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>
<TR>
<TD ALIGN=right NOWRAP>Network printer path:</TD>
<TD ALIGN=left NOWRAP><INPUT type=text id=printerpath name=printerpath
value=//< Domain >/< Printer >></TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP>Login account:</TD>
<TD ALIGN=left NOWRAP><INPUT type=text id=username name=username
value=<% = strUsername %>></TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP>Login Password:</TD>
<TD ALIGN=left NOWRAP><INPUT type=password id=password
name=password></TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP>Please enter the text you want to print:</TD>
<TD ALIGN=left NOWRAP><TEXTAREA rows=2 cols=20 id=message
name=message></TEXTAREA></TD>
</TR>
<TR>
<TD ALIGN=right NOWRAP> </TD>
<TD ALIGN=left NOWRAP><INPUT type=submit value=Submit
id=submit name=submit></TD>
</TR>
</TABLE>
</FORM>
When the above information is submitted, you can print it according to the following code.
<%
Else
' Get response information from form.
strPrinterPath = Request.Form(printerpath)
strUsername = Request.Form(username)
strPassword = Request.Form(password)
strMessage = Request.Form(message)
We will now use the VBScript FileSystemObject object and the WSH Network object. The Network object will
give us the methods we need to open a printer connection, and the FileSystemObject will allow us to stream our
output to the printer. We create these objects in the following code example:
Set objFS = CreateObject(Scripting.FileSystemObject)
Set objWSHNet = CreateObject(WScript.Network)
' Connect to a network printer using WSH
objWSHNet.AddPrinterConnection LPT1, strPrinterPath, False, strUsername, strPassword
'Use the file system object to use the printing device as a file
Set objPrinter = objFS.CreateTextFile(LPT1:, True)
'Send text to the printing device
objPrinter.Write(strMessage)
'Close the print device object and perform error trap processing
On Error Resume Next
objPrinter.Close
' If an error occurs, close the print connection and output the error message
If Err Then
Response.Write (Error # & CStr(Err.Number) & & Err.Description)
Err.Clear
Else
'The operation is successful, output confirmation information
Response.Write(<CENTER>)
Response.Write(<TABLE WIDTH=100% ALIGN=center BORDER=0 CELLSPACING=1 CELLPADDING=1>)
Response.Write(<TR><TD ALIGN=RIGHT><B>Print message send:</B></TD>)
Response.Write(<TD ALIGN=LEFT> & strMessage & </TD></TR>)
Response.Write(<TR><TD ALIGN=RIGHT><B>Network printer path:</B></TD>)
Response.Write(<TD ALIGN=LEFT> & strPrinterPath & </TD></TR>)
Response.Write(<TR><TD ALIGN=RIGHT><B>Login account:</B></TD>)
Response.Write(<TD ALIGN=LEFT> & strUsername & </TD></TR>)
Response.Write(</TABLE>)
Response.Write(</CENTER>)
End If
' Cancel the print connection
objWSHNet.RemovePrinterConnection LPT1:
Set objWSHNet = Nothing
Set objFS = Nothing
Set objPrinter = Nothing
End If
%>
</BODY>
</HTML>
Share: ASP integrates a SQL statement class When writing an asp database program, we usually use SQL statements, and when adding and updating data, we usually use the following method: insert into message (incept,sender,title,content,sendtime,flag,issend) values ('incept(i)','membername','title','message',Now(),0,1) When there are many fields