tomcat-taglibs-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ben Ramsey" <...@eureka-interactive.com>
Subject RE: Google Search Tag
Date Tue, 20 Aug 2002 14:13:38 GMT
> I just got to hear about the Google API , and I would like
> to know how to call the api from my jsp pages or servlets.

Make sure the google api jar file is in your /WEB-INF/lib directory first
and restart Tomcat.  Then, in the page you want to use it, you call it with
something like this:

<%@ page language="java"
import="com.google.soap.search.*,java.io.*,java.net.*" errorPage=""
contentType="text/html; charset=iso-8859-1" %>

You can figure out how to code it yourself, but because I had such a fun
time figuring it out on my own, I'll help you get started:

<%
  GoogleSearch gs = new GoogleSearch();
  gs.setKey("#############################");
  gs.setQueryString(request.getParameter("keywords"));
  GoogleSearchResult gsr = gs.doSearch();
  GoogleSearchResultElement gsre[] = gsr.getResultElements();
  for(i=0; i < gsre.length; i++) {
    out.print("<p><a href=\"");
    out.print(gsre[i].getURL());
    out.print("\">");
    out.print(gsre[i].getTitle());
    out.println("</a><br />");
    out.print(gsre[i].getSnippet());
    out.println("</p>");
  }
%>

That should be enough to get you started.  You can customize it as you wish
by looking at the Google API documentation (this should've been in the API
download).


Ben Ramsey
Technical Director
EUREKA! Interactive, Inc.
770-642-0390
www.eureka-interactive.com


--
To unsubscribe, e-mail:   <mailto:taglibs-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:taglibs-user-help@jakarta.apache.org>


Mime
View raw message