jsp搜索引擎
更新時(shí)間:2006年10月13日 00:00: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[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);
}
}
您可能感興趣的文章:
- jsp網(wǎng)頁(yè)搜索結(jié)果中實(shí)現(xiàn)選中一行使其高亮
- jsp源碼實(shí)例4(搜索引擎)
- php+ajax做仿百度搜索下拉自動(dòng)提示框(有實(shí)例)
- asp+ajax仿google搜索提示效果代碼
- jquery創(chuàng)建一個(gè)ajax關(guān)鍵詞數(shù)據(jù)搜索實(shí)現(xiàn)思路
- asp.net和ajax實(shí)現(xiàn)智能搜索功能代碼
- ThinkPHP實(shí)現(xiàn)ajax仿官網(wǎng)搜索功能實(shí)例
- php+ajax實(shí)時(shí)輸入自動(dòng)搜索匹配的方法
- ajax Suggest類(lèi)似google的搜索提示效果
- Ajax+Servlet+jsp顯示搜索效果
相關(guān)文章
Struts2.5 利用Ajax將json數(shù)據(jù)傳值到JSP的實(shí)例
下面小編就為大家?guī)?lái)一篇Struts2.5 利用Ajax將json數(shù)據(jù)傳值到JSP的實(shí)例。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-09-09JSP Spring 自動(dòng)化裝配Bean實(shí)例詳解
這篇文章主要介紹了JSP Spring 自動(dòng)化裝配Bean實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下2017-04-04JSP + ajax實(shí)現(xiàn)輸入框自動(dòng)補(bǔ)全功能 實(shí)例代碼
給別人說(shuō)ajax技術(shù)時(shí),如果覺(jué)得說(shuō)不明白總會(huì)這樣解釋?zhuān)嚎吹桨俣仁醉?yè)了嗎?你打上一個(gè)字,輸入框下面會(huì)出來(lái)相關(guān)的一些選項(xiàng),那就是ajax技術(shù)。其實(shí)web上所有的異步更新技術(shù)都是通過(guò)ajax技術(shù)實(shí)現(xiàn)的。2013-06-06基于javaweb+jsp實(shí)現(xiàn)學(xué)生宿舍管理系統(tǒng)
這篇文章主要介紹了基于javaweb+jsp實(shí)現(xiàn)的學(xué)生宿舍管理系統(tǒng)的示例代碼,文中的代碼介紹詳細(xì),對(duì)我們學(xué)習(xí)JSP有一定的幫助,需要的朋友可以參考一下2021-12-12JSP實(shí)現(xiàn)在線考試與成績(jī)?cè)u(píng)測(cè)
這篇文章主要為大家詳細(xì)介紹了JSP實(shí)現(xiàn)在線考試與成績(jī)?cè)u(píng)測(cè),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-10-10jsp連接MySQL操作GIS地圖數(shù)據(jù)實(shí)現(xiàn)添加point的功能代碼
本文為大家介紹下使用jsp連接MySQL操作GIS地圖數(shù)據(jù)并實(shí)現(xiàn)添加point的功能,思路及代碼如下,感興趣的朋友可以參考下2013-08-08