?? 0081.htm
字號(hào):
<html>
<head>
<title>新時(shí)代軟件教程:操作系統(tǒng) 主頁(yè)制作 服務(wù)器 設(shè)計(jì)軟件 網(wǎng)絡(luò)技術(shù) 編程語(yǔ)言 文字編輯</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
<!--
body, table {font-size: 9pt; font-family: 宋體}
a {text-decoration:none}
a:hover {color: red;text-decoration:underline}
.1 {background-color: rgb(245,245,245)}
-->
</style>
</head>
<p align="center"><script src="../../1.js"></script></a>
<p align="center"><big><strong>jsp源碼實(shí)例5(搜索引擎)</strong></big></p>
<div align="right">(文/blackwhites)</div>
<p>
package coreservlets;<br>
<br>
import java.io.*;<br>
import javax.servlet.*;<br>
import javax.servlet.http.*;<br>
import java.net.*;<br>
<br>
<br>
public class SearchEngines extends HttpServlet {<br>
public void doGet(HttpServletRequest request,<br>
HttpServletResponse response)<br>
throws ServletException, IOException {<br>
String searchString = request.getParameter("searchString");<br>
if ((searchString == null) ||<br>
(searchString.length() == 0)) {<br>
reportProblem(response, "Missing search string.");<br>
return;<br>
}<br>
// The URLEncoder changes spaces to "+" signs and other<br>
// non-alphanumeric characters to "%XY", where XY is the<br>
// hex value of the ASCII (or ISO Latin-1) character.<br>
// Browsers always URL-encode form values, so the<br>
// getParameter method decodes automatically. But since<br>
// we're just passing this on to another server, we need to<br>
// re-encode it.<br>
searchString = URLEncoder.encode(searchString);<br>
String numResults = request.getParameter("numResults");<br>
if ((numResults == null) ||<br>
(numResults.equals("0")) ||<br>
(numResults.length() == 0)) {<br>
numResults = "10";<br>
}<br>
String searchEngine =<br>
request.getParameter("searchEngine");<br>
if (searchEngine == null) {<br>
reportProblem(response, "Missing search engine name.");<br>
return;<br>
}<br>
SearchSpec[] commonSpecs = SearchSpec.getCommonSpecs();<br>
for(int i=0; i<commonSpecs.length; i++) {<br>
SearchSpec searchSpec = commonSpecs[i];<br>
if (searchSpec.getName().equals(searchEngine)) {<br>
String url =<br>
searchSpec.makeURL(searchString, numResults);<br>
response.sendRedirect(url);<br>
return;<br>
}<br>
}<br>
reportProblem(response, "Unrecognized search engine.");<br>
}<br>
<br>
private void reportProblem(HttpServletResponse response,<br>
String message)<br>
throws IOException {<br>
response.sendError(response.SC_NOT_FOUND,<br>
"<H2>" + message + "</H2>");<br>
}<br>
<br>
public void doPost(HttpServletRequest request,<br>
HttpServletResponse response)<br>
throws ServletException, IOException {<br>
doGet(request, response);<br>
}<br>
}<br>
</p>
</table>
<p align="center"><script src="../../2.js"></script></a>
</body>
</html>
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -