How to write the code for searching the text in html pages in jsp or java. Actually i had lots of html links and i have to enter the keyword(string) in the search box and that keyword should check all of my html pages and that that links should be displayed on my browser. I'm unable to write this code in jsp, if u had the solution please help me to solve this problem. Thanks and Regards, swapna.
public class SearchText { public static void main(String[] arguments) { int exitCode = 0; try { //String rootURL = "C:\\Viswa-GB\\MyJava\\"; String rootURL ="C:\\TODO\\";
File dir = new File(rootURL); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i=0; i<children.length; i++) { // Get filename of file or directory String filename = children; String line = null; //System.out.println(rootURL+filename + "-------------------------------") ; BufferedReader file = new BufferedReader(new FileReader(rootURL+filename)); while ((line = file.readLine()) != null) { System.out.println(line); boolean found = line.contentEquals(new StringBuffer("contains")); if(found) { System.out.println("String FOUND at" + rootURL + filename); //System.exit(exitCode); } else { System.out.println("String NOT FOUND" + i); } } file.close(); } }
public class SearchText { public static void main(String[] arguments) { int exitCode = 0; try { String rootURL = "C:\\1Viswa-GB1\\Test\\"; String searchText = "Web"; File dir = new File(rootURL); String[] children = dir.list(); if (children == null) { // Either dir does not exist or is not a directory } else { for (int i=0; i<children.length; i++) { // Get filename of file or directory String filename = children; String line = null; BufferedReader file = new BufferedReader(new FileReader(rootURL+filename)); while ((line = file.readLine()) != null) { StringTokenizer st = new StringTokenizer(line); while (st.hasMoreTokens()) { boolean found = searchText.equalsIgnoreCase(st.nextToken()); if(found) { System.out.println("String Found @ " + rootURL + filename); } } }