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


public class SearchEngines extends HttpServlet {
public void doGet(HttpServletRequest " /> 中文字幕精品www乱入免费视频,国产高清自产拍av在线,欧美与欧洲交xxxx免费观看

色尼玛亚洲综合影院,亚洲3atv精品一区二区三区,麻豆freexxxx性91精品,欧美在线91

jsp源碼實(shí)例4(搜索引擎)

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技術(shù)jsp源碼實(shí)例4(搜索引擎),轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 海盐县| 噶尔县| 阿巴嘎旗| 万州区| 门头沟区| 马鞍山市| 和静县| 施甸县| 额敏县| 岳池县| 普宁市| 友谊县| 南京市| 新平| 那曲县| 福建省| 广州市| 华宁县| 乌鲁木齐市| 通州区| 新干县| 阳山县| 汤阴县| 光山县| 柏乡县| 塔城市| 普安县| 丹凤县| 韶关市| 昌乐县| 准格尔旗| 昌乐县| 蒲城县| 湘潭市| 鄯善县| 河曲县| 铜梁县| 万山特区| 蒙城县| 怀化市| 淳化县|