Adnan Zakir <[EMAIL PROTECTED]> wrote:

>Hi erverybody,

>    I want to write a servlet that will help me search html
>files on a machine, something like a search engine. How can
>I do this using servlets?



Something like this might work [adapted from the Finger example in Jason
Hunter's Java Servlet Programming book <http://www.servlets.com/>
<http://www.oreilly.com/catalog/jservlet/index.html>]:


Process process = Runtime.exec( new String[] { "grep", "-dlw", searchString,
"*.html" } );
DataInputStream in = new DataInputStream( process.getInputStream() );
PrintWriter out = servletResponse.getWriter();

String result = null;
String url = null;
while ( ( result = in.readLine() ) != null )
{
    url = "/" + result.substring(6).replace( '/', '\\' );
    out.println( "<a href=\"" + url + "\">" + url + "</a><br>" );
}


It isn't very efficient, but it might get the job done. It also assumes you
are using a PC (the replace() makes the slashes go the right way) and that
you are using the exact same version of grep that I have. Otherwise you'll
have to modify it a bit. Plus I haven't tested it, so it might not work at
all.  :)

Otherwise, you could do what I've been doing the past few days and write a
program that indexes the site each night and a servlet that searches the
index.


Erik

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to