import java.io.IOException;
import java.io.PrintWriter;
import java.util.ArrayList;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Search Google.
 * 
 * @author Jose Sandoval
 */
public class MyGoogleSearchServlet extends HttpServlet {
	/**
	 * Do get.
	 * 
	 * @param request HttpServletRequest
	 * @param response HttpServletResponse
	 * @throws ServletException, IOExeption
	 */
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		PrintWriter out = response.getWriter();
		StringBuffer resultBuffer = new StringBuffer();
		ArrayList results = MyGoogleSearch.doSearch(request.getParameter("search"));
		SearchResultBean resultBean = null;
		
		for (int i = 0; i<results.size(); i++) {
			resultBean = (SearchResultBean) results.get(i);
			resultBuffer.append("<a href=").append(resultBean.getURL()).append(">").append(resultBean.getTitle()).append("</a>");
			resultBuffer.append("<br>");
			resultBuffer.append(resultBean.getSnippet());
			resultBuffer.append("<br>").append("<br>");
		}
		
		response.setContentType("text/html");
		response.setHeader("Pragma", "no-cache");
		response.setHeader("Expires", "0");
		response.setHeader("Cache-Control", "no-store");
		
		out.print(resultBuffer.toString());
		out.close();
	}
}
Syntax Highlighting created using the com.Ostermiller.Syntax package.
Sunday, March 20 2005 at 00:43