您的位置:首页-> 技术开发-> JSP学院-> jsp源码实例4(搜索引擎)

jsp源码实例4(搜索引擎)
作者:admin 时间:2000-12-10  来自:ASP教程  选择阅读文体:


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);
}
}



上一篇:jsp源码实例5(cookie) 下一篇:jsp源码实例3(获取jsp各种参数)

GoogLe中搜索“jsp源码实例4(搜索引擎)”相关内容...
百 度 中搜索“jsp源码实例4(搜索引擎)”相关内容...
一 搜 中搜索“jsp源码实例4(搜索引擎)”相关内容...

相关文章

.Net专栏
Script
ASP学院
PHP学院
Web服务器
CGI学院
XML学院
SQL学院
JSP学院
SMS学院
提升QQ等级 QQ挂机升级外挂
国内首发 韩国版QQ自定义头像
挖掘Windows XP系统安装盘中的神秘宝藏
初见photoshop8.0的庐山真面目!
BT下载速度之战:Bitcomet对决比特精灵
腾讯最新漏洞-------QQ红钻任你拿
Windows XP 的安装
如何制作万能DVD
浅谈Windows XP SP2补丁包的安装及使用
RM,RMVB转VCD
购物车的源程序
Eclipse中使用ANT
JAVA/JSP学习系列之一(JDK安装)
Windows下JSP开发环境的配置
Java学习的捷径
J2EE 开发购物网站 经验篇 - 建表
实战 J2EE 开发购物网站 - 创建数据库
实战 J2EE 开发购物网站 二
JSP开发前菜鸟设置篇
用Java实现HTTP文件队列下载