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 in to another server, and 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.");
}
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.