大雀软件园

首页 软件下载 安卓市场 苹果市场 电脑游戏 安卓游戏 文章资讯 驱动下载
技术开发 网页设计 图形图象 数据库 网络媒体 网络安全 站长CLUB 操作系统 媒体动画 安卓相关
当前位置: 首页 -> 技术开发 -> JSP专区 -> jsp搜索引擎

jsp搜索引擎

时间: 2021-07-31 作者:daque

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[i]; 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); } } 

热门阅览

最新排行

Copyright © 2019-2021 大雀软件园(www.daque.cn) All Rights Reserved.