engine

原创 2005年03月01日 22:19:00


/*
 该程序模拟搜索引擎的实现过程。用本程序接受搜索引擎搜索到的结果
 然后对字符串进行处理,最后在输出页面给用户。

 */
package common.engine;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.regex.*;
public class Engine extends HttpServlet {

    public void doGet(HttpServletRequest request,
                      HttpServletResponse response)
        throws IOException,ServletException {
        String strStartPage="";
        String strName;
        int m=0;
        byte[] buffer=new byte[2500];
        String temp="";
        InputStream input=null;
        String www="href='/DaLianNetWeb/engine";
        strName=(String)request.getParameter("word");
        strStartPage=request.getParameter("page");
       
     
     //   byte[] strkkk=strName.getBytes("ISO8859-1");
    
//        byte[] strkkk=strName.getBytes("iso8859-1","gb2312");       
//        String strKEY=new String(strkkk);

       strName=new String(strName.getBytes("iso8859-1"),"gb2312");
       String strKEY;
       strKEY=strName;
      
        ServletOutputStream ow=response.getOutputStream();
        OutputStreamWriter out=new OutputStreamWriter(ow,"GB2312");
        out.write("<!DOCTYPE HTML PUBLIC /"-//W3C//DTD HTML 4.01 Transitional//EN/" /"http://www.w3.org/TR/html4/loose.dtd/">");
        out.write("<html><head>");
        out.write("<meta http-equiv=/"Content-Type/" content=/"text/html; charset=gb2312/">");
        out.write("<title>大连网搜索</title>");
        out.write("<link href=/"../DaLianNetWeb/common/css/css.css/" rel=/"stylesheet/" type=/"text/css/">");
        out.write("</head><body>");
        out.write("<table width=/"777/" height=/"115/" border=/"0/" cellpadding=/"0/" cellspacing=/"0/" id=/"search-list/">");
        out.write("<tr><td width=/"198/" height=/"71/"><img src=/"../DaLianNetWeb/common/images/logo2.gif/" width=/"198/" height=/"71/"></td>");
        out.write("<td width=/"579/" valign=/"top/" class=/"top-center-1/"><table border=/"0/" cellpadding=/"0/" cellspacing=/"0/" id=/"top-nav/">");
        out.write("<tr><td><a href=/"/DaLianNetWeb/index.html/">网站首页</a></td>");
        out.write("<td><a href=/"/DaLianNetWeb/NetSys/zhineng.htm/">中心简介</a></td>");
        out.write("<td><a href=/"/DaLianNetWeb/Special/zhuantifagui1.html/">行业指导</a></td>");
        out.write("<td><a href=/"/DaLianNetWeb/Special/index.html/">专题资源</a></td>");
        out.write("<td><a href=/"#/">公共数据</a></td>");
        out.write("<td><a href=/"/DaLianNetWeb/search.htm/">大连导航</a></td>");
        out.write("</tr></table></td></tr>");
        out.write("<tr> <td height=/"44/" colspan=/"2/"><table width=/"100%/" border=/"0/" cellpadding=/"0/" cellspacing=/"0/">");
        out.write("<tr><td width=/"637/" height=/"34/" class=/"nav/">");
        out.write("<form name=f1 action=/DaLianNetWeb/engine>");
        out.write(" <div align=/"center/">");
        out.write("<input type=/"text/" name=/"word/" value="+strKEY+" >");//修改
        out.write("&nbsp;&nbsp;&nbsp;");
        out.write("<input type=/"submit/" name=/"Submit/" value=/"大连网搜索/"> ");//修改
        out.write("&nbsp;&nbsp;&nbsp;");
        out.write("<input type=/"submit/" name=/"Submit2/" value=/"在结果中搜索/"> ");
        out.write("</div>");
        out.write("</form>");
        out.write("</td> </tr></table></td></tr></table>");
        out.write("<table width=/"922/"  border=/"0/" cellpadding=/"0/" cellspacing=/"0/" class=/"center-table/" id=/"search-list/">");
        out.write("<tr><td height=/"315/">");
      try{
          URL hp = new URL("http://www.baidu.com/baidu?word=" + strKEY +
                           "&rn=10&pn=" + strStartPage + "");
          URLConnection hpCon = hp.openConnection();
          input = hpCon.getInputStream();
          StringBuffer strTemp = new StringBuffer();
          while ( (m = input.read(buffer, 0, 2500)) != -1) {
            strTemp.append(new String(buffer, 0, m));
          }
          strTemp.delete(0, strTemp.indexOf("<p class=p2>"));
          strTemp.delete(strTemp.lastIndexOf("<br clear=all>"),
                         strTemp.lastIndexOf("</table>"));
          temp = new String(strTemp);
          Pattern pat1 = Pattern.compile("<font  color=/"#666666/">.*?上的更多结果");
          Matcher mc1 = pat1.matcher(temp);
          temp = mc1.replaceAll("");
          Pattern pat2 = Pattern.compile("<font color=#008000>.*?百度快照");
          Matcher mc2 = pat2.matcher(temp);
          temp = mc2.replaceAll("");
          Pattern pat3 = Pattern.compile("color=#008000>.*?推广");
          Matcher mc3 = pat3.matcher(temp);
          temp = mc3.replaceAll("");

          out.write("<table width='95%'><tr><td>" + temp + "</td></tr></table>");
          out.write(" <div align=/"center/">");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=0'>[1]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=10'>[2]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=20'>[3]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=30'>[4]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=40'>[5]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=50'>[6]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=60'>[7]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=70'>[8]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=80'>[9]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=90'>[10]</A>&nbsp");
          out.write("<A " + www + "?&word=" + strKEY +
                    "&rn=10&page=100'>下一页</A>&nbsp");
          out.write("</div>");
          out.write("</td></tr></table>");
          out.write(
              "<table border=/"0/" cellpadding=/"0/" cellspacing=/"0/" id=/"bottom-table/">");
          out.write(
              "<tr><td height=/"34/"><p><strong>大连市信息资源管理中心版权所有</strong></p></td>");
          out.write("</tr>");
          out.write("<tr>");
          out.write("<td>--------- <a href=/"/DaLianNetWeb/NetSys/friend.html/">合作伙伴 </a>"+
                    "<a href=/"/DaLianNetWeb/NetSys/copyright.html/">版权声明 </a>"+
                    "<a href=/"/DaLianNetWeb/NetSys/wangzhan.html/">网站简介 </a>"+
                    "<a href=/"/DaLianNetWeb/NetSys/law.html/">法律声明 </a>"+
                    "<a href=/"/DaLianNetWeb/NetSys/zhineng.htm/">用户指南 </a> "+
                    "---------<span class=/"style5/"></span></td>");
          out.write(" </tr>");
          out.write("</table>");
          out.write("</body>");
          out.write("</html>");
          input.close();

       }catch(Exception e){

          out.write("没有查询结果!");
        }
          out.close();
          ow.close();
    }
 }

相关文章推荐

C#,ArcGIS Engine开发入门教程

目录(?)[+] 利用ArcGIS Engine、VS .NET和Windows控件开发GIS应用 Dixon整理 此过程说明适合那些使用.NET建立和部署应用的开发者,它描述了使用...

Unreal Engine 4 物理模拟之物理碰撞、重叠与射线检测

1、碰撞组件基本属性碰撞组件的属性如图 属性简要介绍: Simulation Generates Hit Events:是否对碰撞事件进行通知 Phys Material Override:指定该Me...

如何使用Azure Container Service Engine在Azure中国区部署容器服务(一):DC/OS篇

如何使用Azure Container Service Engine在Azure中国区部署容器服务(一):DC/OS篇前言什么是Azure Container Service(简称ACS)目前越来越多...

ArcGIS Engine中如何调用GP工具(二)

上一篇文章最后提到过GP工具的许可,这篇文章就详细讲解一下调用GP工具的许可问题,这也是Engine中调用GP工具出错最多的一类问题。除此之外,再介绍一下Engine中如何设置环境变量以及如何调用后台...

oVirt engine备份与恢复官方文档

Backups Backing Up and Restoring oVirt Backing up oVirt - Overview While taking complete ba...
  • kepa520
  • kepa520
  • 2015年12月12日 23:38
  • 901

PaaS平台– Google App Engine的开源实现AppScale环境搭建

搭建环境介绍:硬件平台:HP Z800 工作站  内存:24GB      硬盘:1TB虚拟化环境:XenServer 6.2.0VM1:Ubuntu 12.04 amd64 server | IP:...

Codec Engine 应用开发使用手册

Codec Engine Application Developer User's Guide Literature Number: SPRUE67D September 2007 IMPORTANT...
  • dyzok88
  • dyzok88
  • 2014年12月25日 22:02
  • 1391

编译和运行Codec Engine examples介绍【转】

1. [Optional] Copy the entire "examples" tree out of the product This step is optional, but recom...

DedeTag Engine Create File False提示的种种原因及解决方法

DedeTag Engine Create File False提示的种种原因及解决方法第一种情况:站点、文件夹权限不足造成无法建立文件这种情况的出现,一方面可能是Apache设置的读写权限较严格,另...

Unreal Engine 4(UE4)下载教程

首先登陆到UE官方网站https://www.unrealengine.com  下载EpicGamesLauncherInstaller-2.1.3-2533468.msi文件 按照提示进行安装 ...
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:engine
举报原因:
原因补充:

(最多只允许输入30个字)