The main part of this code will compare the option value and the line read from SearchPage.html to find a match. When you find a match, return the line as a project list item as a project list item as a project list.
IF (Request.GetParameterValues ("QP")! = null) {qpvalues = request.getParameterValues ("QP");
For (int i = 0; i
While (s! = null) {if (s! = null && s.length ()> 0) {if (s.trim (). StartSwith (" 0) {
String Lower = QPVALUES [i] .tolowercase ();
IF (sindexof (QPVALUES [I])> 0 || S.Indexof (Lower)> 0) {results = 1;
IF (VAL == 0) {OUT.PRINTLN (" "); out.println ("
"); Out.Println (QPVALUES [ I]); OUT.Println (" h4>"); out.println (""); val = 1;} out.println (s); Out.println (""); }}}
S = in.readline ();} Val = 0; Out.println (" UL>");
Selection value: no results found
If matching is not found, a corresponding message is returned on the result page. Then the file is reset to the beginning and read the first row to match another option value.
IF (Results == 0) {OUT.Println (" "); out.println ("
"); Out.println ("NO Results Found for " qpvalues [i]); out.println (" h4> ");} else {resultS = 0;} in.seek (0); s = in.readline ();}}
Enter the value: Find the body of the matching code to compare the input values with each of the read searchPage.html to look for match. When you find a match, the row returns a project list item under this category to the result page.
IF (Request.GetParameter ("Qt")! = null) {
QtValue = Request.getParameter ("Qt"); VAL = 0;
In.seek (0);
S = in.readline ();
While (s! = null) {if (s! = null && s.Length ()> 0) {if (s.trim (). startswith (" 0) {
String uppercase = qtValue.toUpperCase (); String lowercase = qtValue.toLowerCase (); String firstletter = qtValue.substring (0,1); String lastletters = qtValue.substring (1); String upfirst = firstletter.toUpperCase (); String INITCAP = Upfirst.concat (Lastletters);
IF (S.indexof>> 0 || S.indexof (LowerCase)> 0 || S.Indexof (Initcap)> 0 || S.Indexof (Uppercase)> 0) {results = 1;
IF (VAL == 0) {Out.Println (""); Out.Println; Out.println ("< / h4> "); out.println ("
Out.println (s); Out.Println ("
");}}}
S = in.readline (); out.println (" ul>");
Enter value: no results found
If you do not find a match, a corresponding message will be returned on the result page.
IF (Results == 0 && QtValue.LENGTLN () (""); Out.println ("" No results Found for " qtvalue); out.println (" h4> "); out.println (" ");} else {results = 0;}} No selected keyword
When the user does not successfully select an option value, it is not successfully entered in the input domain, then it is necessary to return a message on the result page to notify the user.
IF (Request.GetParameter ("qp") == NULL note && qtvalue.Length () == 0) {out.println ("
"); out.println ("no keywords bele selected or entered "); Out.println (" h4> "); out.println ("
");}%>
Capture keywords
You can simply override this program to capture the keywords for end users' choice or entered. The reason for capturing keywords is to understand which is the keyword of the user's most selection or input. If you know a special keyword has been entered many times, then this tells your user's interest, or indicating that this keyword that is often entered may be added to the optional value of the optional sequence.
To capture these keywords, you need to rewrite the code, open an output stream of the file with read and write, and write data to the file. The code for obtaining the option value and the input value is placed on the end of the file, and is written to these values and add a new row character (/ N) between each value to increase readability.
Note: The value obtained by the selection box is written to keywords.txt independently of the UTF character in which the machine is used, as the UTF character is used for the display of the graph.
Findwords.jsp shows all of the code to increase the function.
File outputfile = new file ("/ pathname / keywords.txt"); OUTKW = New RandomaccessFile (OutputFile, "RW");
.
IF (Request.getParameterValues ("QP")! = null) {qpvalues = Request.getParameterValues ("qp"); for (int J = 0; j " qpvalues [j] " "); OUTKW.SEEK (OutputFile.Length ()); OUTKW.WRITEUTF (QPVALUES [J]); OUTKW.WRITEBYTE ('/ n');}}
IF ("qt")! = null) {qtvalue = request.getParameter ("qt"); if (qtvalue.Length ()> 0) {Out.Println ("
QtValue ""); OUTKW.SEEK (OutputFile.Length ()); OUTKW.WRITECHARS (qtvalue); OUTKW.WRITEBYTE ('/ n');}}}
JSP technology makes it easy to write a simple search engine to analyze the keyword matching of the HTML page. This simple example is specific to the HTML page with a certain format, but we can write it easily to use it for web pages in different formats.
Exercise 1
A good exercise is to increase the code, so that regardless of whether formatting a format carrier is placed in the search entry to simplify the data reading, those rows will be read.
Exercise 2
Overwrite this program to read data from one URL connection. You will use the URL class, you can find an example of using this class in the READING DIRECTLY from A URL of the Java Tutorial (Java Tutorial).
About author
Monica Pawlan uses and writes Java programming languages for more than 6 years. She wants to develop and learn knowledge about Australian Native Plants with the remaining free time. She is still the author of the "Java Programming Language] (Addison-Wesley, 2000)," Java 2 Platform Advanced Programming "(ADDISON-WESLE, 2000).
Http://gceclub.sun.com.cn/staticContent/html/0926/2/2-1.html