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;
public class MyGoogleSearchServlet extends HttpServlet {
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();
}
}