Use ASP to implement three powerful functions

Source: Internet
Author: User
Tags case statement

Add a spelling check function for a web site

Many developers have raised the question "How to perform spelling checks on user input content". This article provides a useful method to discuss how to use the xde spelling check component, it can be used as a spelling checker and a dictionary. The good news about this component is that it can be used on the server side or as a Java applet. However, the convenience is not free, and it costs about $100. However, this component provides a 30-day free use evaluation version, so you can carefully test and carefully consider whether to meet your needs before deciding to buy it.

First, visit http://mirrordns.com/download/site, enter some information (name, email, and so on), download and install this component. Next, select the "quick spell check Full Install" project from the multiple xde components available for download. After the download is complete, install it. Before the installation is complete, a registration menu appears. Simply select "evaluation period" by default ".

Note that the current program is in beta version. If you do not want potential errors, we recommend that you download the first official version before testing. I have found some errors in the current version. Remember: This is a beta version and should not be applied on the official site.

Then, prepare the registration component. Decide whether you want to include the dictionary and dictionary functions of Word 97. If you want to, install Word 97 or Word 2000 on the Web server first, then execute a special set of commands with reference to the instructions in the http://mirrordns.com/spellchecker/server_installation.htm. If you do not want to use the entire Word 97 dictionary, perform the following operations just like registering other components:

Copy the DLL file spellcheckserver. DLL to the Windows system or system32 directory.

Use regsvr32 to register the component: regsvr32 spellcheckserver. dll

After installing the component, you can use it in ASP code. To create an example of a spelling check object, simply write the following code:

Set objspellcheck = server. Createobject ("spellcheck. clschecker ")

As I mentioned earlier, this component provides the spelling check and dictionary functions. First, let's see how to return a series of synonyms for a given word. This requires the lookupsynonym method. This method requires a parameter that is used to search for synonyms. After execution, the spelling check object collects related words to the Collection object synonymwords. Run the following code to return all synonyms of the word "quick:

<%

Dim objspellchecker, iloop

'Create an instance of the spellchecker

Set objspellcheck = server. Createobject ("spellcheck. clschecker ")

Objspellchecker. usemsword = false 'we' re not using MSWord

Objspellchecker. lookupsynonym "quick" 'lookup the synonym for "quick"

'Loop through the returned words:

Response. Write "The following synonyms for 'quick' exist :"

For iloop = 1 to objspellchecker. synonymwords ("quick"). suggestedwords. Count

Response. Write objspellchecker. synonymwords ("quick"). suggestedwords (iloop). Word

Response. Write ""

Next

%>

The execution of the spelling check on the server side is very compact on the code structure, but as I can see, to make full use of the powerful functions, you must rely on the Java Applet-form spelling check. The following will focus on how to apply this approach, for methods for using components on the server side, see http://mirrordns.com/spellchecker.

To use a Java Applet, copy the. Class file under the installation directory to a Web accessible directory. For example, move the file to the/spellcheck directory. Then, create a form that contains a text box or text field, which is the content of the spelling check.

<HTML>

<Body>

<Form name = "frmspellcheckexample">

<Textarea name = "javatextarea" rows = "8" Cols = "50"> <p>

<Input type = "button" value = "Start spell check" onclick = "spellcheck ();">

Then, use the applet tag to reference the Java Applet:

<APPLET codebase = "/spellcheck/" code = "spellcheck. Class"

Height = "1" name = "spellcheck" width = "1"

Alt = "applet not displayed">

<Param name = "foreground" value = "ffffff">

<Param name = "background" value = "008080">

<Param name = "label" value = "this string was passed from the HTML host.">

Note: The codebase parameter in the applet tag points to the directory where the. Class file is located.

Finally, use a piece of JavaScript code on the client to assemble the applet parameters:

<Script language = "JavaScript">

Function spellcheck (){

Document. spellcheck. ptexttocheck =

Document. frmspellcheckexample. javatextarea. value;

Document. spellcheck. dodlg ();

If (document. spellcheck. fixedtext! = ""){

Document. frmspellcheckexample. javatextarea. value =

Document. spellcheck. fixedtext;

}

}

This is done! If you want to learn more about how to use this component and Java Applet, take a look at the following: http://mirrordns.com/spellchecker /.

 

Dynamically create a barcode on the Web

This article discusses how to dynamically create a bar code on the web based on database fields, which is useful in the following scenarios: Users enter information to the system, then, a summary page "This Is What You entered" is displayed, which can be printed and tracked by bar code in the future.

The key to implementing this function is how to translate a value such as "ABC" into a bar code. Here we use "code 39". For details about it, see related definitions. I want to display the generated barcode on the Web page so that the user can print the page containing the barcode and then use it in the processing of the Graphic System. Many users have installed the "code 39" font in the system, so I can change it on the page, but I don't want to rely on them. I want to create it on the page and it is independent of browsers and computers.

My solution is to create a GIF image file for each supported character in code39. I use the Microsoft Paint software to create a text box with the code39 font size, and then create a graph for each character. Then, use Microsoft Image composer to convert them to GIF format. Finally, use the Scan software to check these characters to see if they can be correctly interpreted. Next, you will see the bar code of A, B, C, and asterisk:

Code for

Code for B

Code for C

Code For Asterisk

Then, in order to depict the bar code of values in the database on the ASP page, simply traverse every character in the barcodetext variable string, create a flag to replace the character with the corresponding bar code graphic file. This is very simple. You do not need to install the font file on the client. The related code is as follows:

'Code 39 barcodes require an asterisk as the start and stop characters

Response. Write "

For x = 1 to Len (TRIM (RST ("barcodetext ")))

Response. Write "

". GIF" "width =" "30" "Height =" "36" ">"

Next

'Code 39 barcodes require an asterisk as the start and stop characters

Response. Write "

If the barcodetext value in the record set's current record is "ABC", after executing the above Code, the HTML result is:

Then, the image is displayed as follows:

Now, after printing the page, it can be tracked by the barcode scanner.

Note: not all bar codes support all character sets. Code39 is a good and very simple one. It has a variable length and supports all uppercase characters, numbers, asterisks, and 7 special characters. For each character, it uses the same style of 5 lines (2 width 3 narrow) 4 blank (pointing gap, 1 width 3 narrow) form. In addition, the character set supports more and uses different decoding schemes. Make sure you have created a GIF image file for each character. At the same time, you can modify the width and height attributes of the image to display a slightly larger or smaller bar code on the page.

In addition, in case of a special website, the upload code will not work, and the GIF file name cannot be designated as pai.gif. In this case, you need to write a function that accepts ASCII values, and then use the case statement to return a string equivalent to the object name. If the database field value is an integer or only contains characters or numbers, the above traversal code is good!

The method described above is not very complex, but in some aspects it is very simple and easy to use.

 

How to hide pages to prevent searching

On the Internet, use some small programs for the search engine we navigate to, such as the 'robots', 'bots', 'crawlers', and 'spiders' we know, to index pages. However, when developing a site, especially ASP for development, it is very useful to prevent page indexing. When these search engines are reviewing their solutions to dynamically index the created web pages, such as ASP pages, this article will help you learn some important techniques to avoid robots from tracking pages that you are reluctant to index.

Why is this related to you?

For example, you have accessed the XYZ website and used the familiar search engine to search for 'xyz Corp. If you find that your management page is also in the relevant chain table, you will be a little worried. If you have an e-commerce site, you do not want to get the URL of the last page of the site before the user ends the page. Not only do network administrators do not want it to happen. For users, it is also troublesome for some pages to run normally, or because they do not have proper permissions or because they do not access the pages in the set order. This is not conducive to the reputation of your site. This is also related to the operators of commercial search engines. Because they want to provide accurate links to improve the service.

So, how can we prevent these programs from indexing some pages on your site? You can choose between two types. One is to include a file named robots.txt in the root directory, or use the <meta> flag.

Include a robots.txt File

As early as 1994, an automatic mail sending list jointly proposed an agreement to prevent robots from dragging sites. However, this is not a formal standard. It does not provide execution guarantees, but is used by many robot authors.

It is very simple to create a robots.txt file, which indicates the expected robot behavior standards of network administrators. Note that the file name must contain lowercase letters and must be placed in the root folder of the site, such as http: // xyzcorp/robots.txt, so that a file can take out all the details of the entire site.
What is in a robots.txt file?

Each robots.txt file contains one or more records. A record consists of a robot user proxy string, that is, the indication you are willing to follow and the indication applied to it. Don't worry, you need to know all the Robot User proxy strings roaming in the Web, because you can use the wildcard * to apply all the robots. The following is an example of a record:

User-Agent :*

Disallow:/xyzfinances. asp

Disallow:/admin

Disallow:/news/update. asp

In addition to the user's proxy string/wildcard, you only need to include a disallow command. This simple example shows all the possibilities you will need. It indicates that no user agent string can enter xyzfinances. asp, expressed in this line:

Disallow:/xyzfinances. asp

Or the user agent string cannot enter the management folder and all the folders below it:

Disallow:/admin

Or the update. asp file in the News folder, if all other content in the News folder can be indexed.

In a record, you can specify the user proxy string name. In any robots.txt file, you can specify the number of records you want to include (as long as one or more blank lines are used to separate these records ).

Each individual record may provide different instructions for one or more robots. However, it is wise to add a wildcard rule for engines that do not use the name of the user proxy string. The most popular choice is to maintain a scheme represented by a record and a wildcard representing the user's proxy string. For a list of 196 user proxies, refer

Http://info.webcrawler.com/mak/projects/robots/robots.html.

It is generally believed that robots should ignore the case and version numbers. Remember that this is the opinion of the robots authors of most commercial search engines, because you don't want to use useless pages to upset users. However, although you do not need to consider case sensitivity in the command line, you must ensure that the URL is accurate when you type the URL. Although Windows NT is case insensitive to the file name and path name, not all platforms do.

The other things you want to include are only comments. These use the Unix Bourne shell protocol. For example, the # symbol represents a blank space before the hash symbol, and the remaining parts that can be ignored in a line. If a row contains only one comment, it can be completely ignored, although it acts differently between records and empty rows.
Now let's take a look at two final examples.

Example 1

# Don't come to this site

User-Agent :*

Disallow:/# disallows anything

Example 2

# Robots.txt for xyzcorp

# Webmaster: John Doe contact JohnD@xyzcorp.com

User-Agent: * # applies to all robots before t next record

Disallow:/store/order/# No robot shocould visit any URL starting

/Store/order/

Disallow:/admin/# disallow any pages in the admin folder

Disallow:/world_domination.asp # disallow world_domination.asp

All the contents of the robot.txt file are closed here.

The following describes how to use the <meta> tag.

Use a <meta> robot flag

Similarly, you still cannot guarantee that a robot will fully comply with the instructions in the <meta> tag, but it is very effective for commercial search engines. <Meta> the tag must be included in the

Similarly, the syntax is very simple. The first example is:

<Meta name = "Robots" content = "noindex">

This line of code tells robot not to index this page.

Next example:

<Meta name = "Robots" content = "nofollow">

Allow the robot to index this page, but it requires that it cannot follow any link on this page. If you want to disable both, you can use:

<Meta name = "Robots" content = "noindex, nofollow">

This means that you do not want to index this page or follow any links on this page. However, there is a simpler method:

<Meta name = "Robots" content = "NONE">

Or does it mean not to index this page or follow any links on this page.

Unfortunately, if you have a file named admin. asp that is linked to update. asp, use <meta>

Mark to prevent robot from indexing Admin. asp or update. asp, but forget

The same processing is also done on the page, so the robot can still reach update. asp by missing the second page marked by <meta>.

You can also use value indexes. However, since they are ignored by default, this is unnecessary and meaningless.

If you are using IIS, you should always use the custom HTTP header file to execute the <meta> flag method. Theoretically, the response of a robot to the <meta> tag created in this way should be exactly the same, and it looks like this:

<Meta HTTP-EQUIV = "Robots" content = "noindex">

Theoretically, now we can use the custom header file created by IIS for all files or virtual paths in folders or folders. However, this method has not been successfully tested so far. These methods cannot completely hide your page. Indeed, if someone intentionally writes a robot to find your private page, they become pointers to the page the author wants to protect. However, for the prevention of commercial site index pages, these methods still work, and only make sense in this regard.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.