Simple web keyword matching tool

xiaoxiao2021-03-06  61

Simple web keyword matching tool

Author: Monica Pawlan July 2003

Have you used a lot of details to create a web page, and then I hope the reader can use a simple method to analyze and enter the corresponding page according to user-specific keywords. This article explains how to use HTML forms and JSP techniques to correctly implement the above requirements. Even if you have never wanting to get this effect, you may also find the presentation examples and code exercises for this article very useful, because these examples and code covers how to retrieve the requested values ​​and to read these values ​​with the value read in the static file. Compare.

Working principle HTML form search web code training capture keyword

working principle

Anx note this html form has been placed in the page you want to search. This form gives an optional keyword list. These keywords are known in the webpage, do not match your topic, but you believe that users may want to search these words. The form also provides a input domain for the user. If the user does not find the desired keyword in that list, you can enter the keyword he wants in this input domain.

When the user knocked back the vehicle button or clicking the Go button, the JSP is called by line by line, looking for the keyword specified by the user, and returns all the rows that contain keywords in the HTML page. The result of the return is organized according to the keywords match.

HTML form

The following picture shows the HTML form on the left, and the HTML code for creating the form is given. This form is available, you can choose or enter the keyword and click the Go button.

Not after you click on the Go button, a JSP page will be called to analyze a copy of the JavaServer Pages Technology index page and return a list of articles, one or some of these articles contains the specified keyword. For example, if you remember the article written by Steve, enter "Steve" and click the Go button to view the article list of Steve.

Note: This process may last for a few seconds because the search page described below needs to read many headline bars, footnotes, and left navigation HTML code.

Form appearance to achieve HTML of this form

select keywords from the list below:

Search page

This JSP page code requires search page Use paragraph tags to contain. For example, the code of the web entry should be like this is given below. Note that in order to make the HTML page more easy to read, it is not used in the entry code below:

maintaining state for html form button by Matthias Laux
Here's The Scoop ON Using JavaServer Pages Custom Tags To Maintain Button State in Your Html Forms. (October 2002)

Instead, the following example uses a carriage return between "Laux" and "Here's" to ensure that the source file is easier to understand.

maintaining state for html form button by matthias laux
Here's The Scoop ON Using JavaServer Pages Custom Tags To Maintain Button State In Your Html Forms. (October 2002)

Why didn't you return format?

If you don't consider missing a carriage return to formatting like the first example above, the JSP code will read the entire line of data, analyze if there is a keyword, if there is a match existence, then in the result page Return to the whole line. In the second example, the JSP code reads the rows above "Laux", and then analyzes, if there is a match, return to the line in the result page. This code will then read the next line starting with "Here's".

In short, because the entire page is disrupt, there is no completely return to the entire page. In the above example, if the search condition is "maintaining", the result will only return the title and the author without introduction; if the search criterion is "maintain", the result will return an introduction instead of the title and the author.

Code analysis

This section describes each part of Findwords.jsp, and findwords.jsp is the JSP code called when the user clicks on the Go button.

Note: The source code is in a TXT file, so you can use it as text to browse. With the "JSP" suffix means that the web server needs to be compiled into a servlet and execute it.

JSP looks like an HTML page, just in which the servlet code snippet is embedded through the JSP tag. There are many different types of JSP tags that only involve part of this section.

instruction

The JSP instruction is included with the <% @ and%> command tag that is processed by the JSP engine when the JSP page is converted to servlet. The page instruction in this example tells the JSP engine scripting language to be java (language = "java") and needs to contain the specified Java package.

statement

The JSP declaration is included by <%! And%> declared tags, allowing you to set the variable to use it later in the program later. You can also declare the variable when you are using. Just remember that no matter where the variable is declared, its scope is the entire JSP page. The declaration in this example declares a random access file and some string variables used to read the search page.

Set files and variables

The next line of the code initializes the variable, and opens a connection to searchPage.html, searchPage.html is the web page to search. In this example, the file is a copy of the JavaServer Pages Technology Index page. This initialization process obtains the length of the file to be searched, get the first line of the file, and set some variables to 0 or null. The VAL variable is a logo for indicating whether a match is the first in its category, and this judgment is a need to re-establish a match or continue search on an existing sequence. The Results variable is also a logo variable for indicating whether a match is found. If there is no match, return a message to the user on the return page.

FILE INPUTFILE = New File ("/ Pathname / searchPage.html"); in = new randomaccessfile (InputFile, "R");

Long longth = in.Length ();

S = in.readline ();

INT VAL = 0;

INT results = 0; string [] qpvalues ​​= null; string qtvalue = null;

Results page and record entries

The next code is used to print the title of the result web page, check the selected value obtained from the optional sequence ("QP") and the value obtained from the input field from the form (GetParameter)). All values ​​found will be retrieved and used to create a list of items displayed on the top of the result page.

Out.println ("

Keyword Search Results ); Out.Println ("

转载请注明原文地址:https://www.9cbs.com/read-119939.html

New Post(0)