动网论坛,站长建站首选,国内使用量最多的论坛软件 动网论坛官方技术讨论区 站长工具 申请属于您自己的免费论坛
首页 | 新闻资讯 | 网站运营 | 网络编程 | 数据库 | 服务器 | 网页设计 | 图像媒体 | 网络应用 | 搜索优化 | 资源下载 | 动网主机 | DVBOX
    本站内  互联网 ASP论坛  ASP.Net论坛  PHP论坛
  
   Asp → 阅读文章

 jsp源码实例4(搜索引擎)

作者来源: 
阅读 1523 人次 , 2006-3-29 4:22:00 


package coreservlets;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;

public class searchengines 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, "missing search string.");
return;
}
// the urlencoder changes spaces to "+" signs and other
// non-alphanumeric characters to "%xy", where xy is the
// hex value of the ascii (or iso latin-1) character.
// browsers always url-encode form values, so the
// getparameter method decodes automatically. but since
// we're just passing this on to another server, we need to
// re-encode it.
searchstring = urlencoder.encode(searchstring);
string numresults = request.getparameter("numresults");
if ((numresults == null) //
(numresults.equals("0")) //
(numresults.length() == 0)) {
numresults = "10";
}
string searchengine =
request.getparameter("searchengine");
if (searchengine == null) {
reportproblem(response, "missing search engine name.");
return;
}
searchspec[] commonspecs = searchspec.getcommonspecs();
for(int i=0; i<commonspecs.length; i++) {
searchspec searchspec = commonspecs;
if (searchspec.getname().equals(searchengine)) {
string url =
searchspec.makeurl(searchstring, numresults);
response.sendredirect(url);
return;
}
}
reportproblem(response, "unrecognized search engine.");
}

private void reportproblem(httpservletresponse response,
string message)
throws ioexception {
response.senderror(response.sc_not_found,
"<h2>" + message + "</h2>");
}

public void dopost(httpservletrequest request,
httpservletresponse response)
throws servletexception, ioexception {
doget(request, response);
}
}

 本文Tags索引  
 收藏本文  打印本文  论坛讨论  关闭窗口
· 上一篇:jsp源码实例5(cookie)
· 下一篇:jsp源码实例3(获取jsp各种参数)
· ASP 3.0高级编程(三)
· 浅谈数据库接口技术
· 我需要多大马力?(自MS)--IIS的配置需求
· asp列出sql数据库中(PUBS数据库)存贮过程及其例子
· 聊天室实现私聊(三)


关于本站 | 联系我们 | 业务合作 | 客户案例 | 诚聘英才 | 广告合作 | 收藏本站
海口动网先锋网络科技有限公司版权所有
Copyright © 2000 - 2006 Cndw.Com
中华人民共和国电信与信息服务业务经营许可证编号 琼 ICP 020077