日期:2014-05-18  浏览次数:20778 次

关于连接搜索引擎
这是在tomcat下面的:
出现404和500错误:
________________________________
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN ">
<HTML>
<HEAD>
<TITLE>   New   Document   </TITLE>
<META   NAME= "Generator "   CONTENT= "EditPlus ">
<META   NAME= "Author "   CONTENT= " ">
<META   NAME= "Keywords "   CONTENT= " ">
<META   NAME= "Description "   CONTENT= " ">
</HEAD>

<BODY>
<FORM   METHOD=POST   ACTION= "http://127.0.0.1:8080/myweb/search ">
<INPUT   TYPE= "text "   NAME= "searchString "> <br>
<INPUT   TYPE= "text "   NAME= "numResults "   value=10   size=3> <br>
<INPUT   TYPE= "radio "   NAME= "searchEngine "   value= "goole ">
<INPUT   TYPE= "submit "   value= "search ">

</FORM>

</BODY>
</HTML>
___________________________________
servlet   :
import   java.io.*;
import   javax.servlet.*;
import   javax.servlet.http.*;
import   java.net.*;
public   class   search   extends   HttpServlet
{
public   void   doGet(HttpServletRequest   request,HttpServletResponse   response)
throws   ServletException,IOException
{
String   searchString   =   request.getParameter( "searchString ");
if(searchString==null&&searchString.length()==0)
{
                          reportProblem(response, "miss   searchString ");
  return;
}
searchString   =   URLEncoder.encode(searchString);
String     searchEngine   =   request.getParameter( "searchEngine ");
if(searchEngine   ==   null)
{
reportProblem(response, "miss   searchEngine ");
}
              SearchSpec[]   commonSpecs   =   SearchSpec.getCommonSpecs();
      for(int   i   =   0;i <commonSpecs.length;   i++)
{
      SearchSpec   searchSpec   =   commonSpecs[i];
      if(searchSpec.getName().equals(searchEngine))
{
      String   url   =   searchSpec.makeURL(searchString, "10 ");
      response.sendRedirect(url);
      return;
      }
      }
      reportProblem(response, "Can 't   search   engine ");

}

private   void   reportProblem(HttpServletResponse   response,String   message)
throws   ServletException,IOException
{
                  response.sendError(response.SC_NOT_FOUND, " <H2> "+message+ " </H2> ");

}

&n