Google Tag Library

  • 投稿日:
  • by

 JavaWorldの2004/1月号にGoogle Tag Library の記事があったので試してみた。
 まずは、Google Tag Library から Libraryをダウンロードし、 Google Web APIsのサイトで、 license keyの登録/取得が必要である。
 
 ダウンロードした、google-taglib-1.0.1.tar.gz のgoogle.jar と google.tld をWEB-INF/libなどへコピーする。

 web.xmlを下記のように設定し、(license keyは取得したモノを設定する)

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
<context-param>
<param-name>google_key</param-name>
<param-value>license key</param-value>
</context-param>
<taglib>
<taglib-uri>/google-taglib <taglib-location>/WEB-INF/lib/google.tld</taglib-location>
</taglib>
</web-app>


 入力フォームを下記のようにして、
<form target="_blank" action="results.jsp" >
<input type="text" name="q">
<input type="submit" >
</form>


 JSP(results.jsp)を下記のようにし、フォームから実行すれば動作します。
<%@ page contentType="text/html; charset=UTF-8"%>
<%@taglib uri="/google-taglib" prefix="google"%>
<google:search/>
<ol>
<google:searchResult>
<li><google:element name="title-url"/></li>
</google:searchResult>
</ol>

 
※サンプル