Copyright 2003 Sun Microsystems, Inc. ALL RIGHTS RESERVED
Use of this software is authorized pursuant to the terms
of the license found at
http://developer.java.sun.com/berkeley_license.html
<%@ page language="java" import="java.util.*, java.io.*"
%>
<%! RandomAccessFile in = null; %>
<%! RandomAccessFile outkw = null; %>
<%! String s = null; %>
<%
File inputFile = new File("dir/path/name/searchpage.html");
File outputFile = new File("dir/path/name/keywords.txt");
in = new RandomAccessFile(inputFile, "r");
outkw = new RandomAccessFile(outputFile, "rw");
long length = in.length();
s = in.readLine();
int val = 0;
int results = 0;
String[] qpValues = null;
String qtValue = null;
out.println("Keyword Search Results
");
out.println("");
if(request.getParameterValues("qp") != null) {
qpValues = request.getParameterValues("qp");
for(int j = 0; j < qpValues.length; j++) {
out.println("- " + qpValues[j] + "");
outkw.seek(outputFile.length());
outkw.writeUTF(qpValues[j]);
outkw.writeByte('\n');
}
}
if(request.getParameter("qt") != null) {
qtValue=request.getParameter("qt");
if(qtValue.length() > 0) {
out.println("
- " + qtValue + "");
outkw.seek(outputFile.length());
outkw.writeChars(qtValue);
outkw.writeByte('\n');
}
}
out.println("
");
if(request.getParameterValues("qp") != null) {
qpValues = request.getParameterValues("qp");
for (int i = 0; i < qpValues.length; i++) {
while(s!=null) {
if(s != null && s.length() > 0 ) {
if(s.trim().startsWith(" 0) {
String lower = qpValues[i].toLowerCase();
if(s.indexOf(qpValues[i]) > 0 || s.indexOf(lower) > 0) {
results=1;
if(val == 0) {
out.println("");
out.println("");
out.println(qpValues[i]);
out.println("
");
out.println("");
if(results==0) {
out.println("");
out.println("");
out.println("No results found for " + qpValues[i]);
out.println("
");
} else {
results=0;
}
in.seek(0);
s = in.readLine();
}
}
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(qtValue) > 0 ||
s.indexOf(lowercase) > 0 ||
s.indexOf(initcap) > 0 ||
s.indexOf(uppercase) > 0) {
results=1;
if(val == 0) {
out.println("");
out.println("");
out.println(qtValue);
out.println("
");
out.println("");
if(results==0 && qtValue.length() > 0) {
out.println("");
out.println("");
out.println("No results found for " + qtValue);
out.println("
");
out.println("");
} else {
results=0;
}
}
if(request.getParameter("qp") == null && qtValue.length() == 0) {
out.println("
");
out.println("No Keywords were selected or entered.");
out.println("
");
out.println("");
}
%>
Back
to Keyword Search Tool article.