jsp源码实例
发表于:2007-07-04来源:作者:点击数:
标签:
做最专业的JSP中文网站 当前位置:首页--文章分类--JSP技术--JSP基础 文章搜索: 关键字 标题 内容 JSPCN文章目录分类 上传问题 [8] 时间相关 [3] 文件操作 [58] STRUTS [61] 中文问题 [16] 数据库 [115] JAVAMAIL [36] 开发工具 [8] JSP基础 [127] JSP其他
做最专业的JSP中文网站 当前位置:首页--文章分类--JSP技术--JSP基础
文章搜索:
关键字 标题 内容
JSPCN文章目录分类
上传问题 [8] 时间相关 [3]
文件操作 [58] STRUTS [61]
中文问题 [16] 数据库 [115]
JAVAMAIL [36] 开发工具 [8]
JSP基础 [127] JSP其他 [40]
教程系列 [87] JAVABEAN [5]
图片声音 [8] JSP实例 [22]
JSP配置 [54] Java API [20]
考试相关 [38] APPLET [57]
JAVA类 [113] Application [6]
Swing [11] J2EE [108]
异常处理 [11] Servlet [33]
JAVA基础 [166] JAVA实例 [56]
JAVA
网络 [38] EJB [145]
声音图片 [27] XML [80]
JAVA线程 [38] J2ME [65]
SUN [89] B/S其他 [3]
B/S开发 [12] 原子代码 [3]
代码收集 [6] RESIN [21]
JBOSS [11] weblogic [34]
eclipse [12] Tomcat [60]
Jbuilder [29] MYSQL [19]
ORACLE [46] sql server [4]
WWW服务 [2] 邮件服务 [4]
热点文章链接
Java/jsp 好的入门文章共赏 [10681]
JSP学习心得 [6957]
JSP开发入门 [3451]
JSP语法详解 [2824]
JSP实践要点 [2470]
指南:想成为一个JSP网站
程序员吗? [2074]
初学jsp心得 [1978]
JSP中的COOKIE操作 [1946]
详细的jsp分页(
oracle+jsp+apache) [1934]
处理Cookie [1886]
jsp基础学习资料 [1733]
JSP语法简表 [1633]
一个开发人员眼中的JSP技术 [1633]
用JSP操作Cookie [1592]
JSP入门教程(1) [1416]
相关文章链接
jsp源码实例
作者:未知 文章来源:www.jspcn
.net访问次数: 次 加入时间:2005-01-19
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
// were 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);
}
}
原文转自:http://www.ltesting.net