Jsp search engine _ MySQL

Source: Internet
Author: User
Tags alphanumeric characters
Listener; importjava. io. *; importjavax. servlet. *; importjavax. servlet. http. *; importjava.net. *; listener {publicvoiddoGet (HttpServletRequestrequest, listener) throwsServletException, IOE
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
// Hex value of the ASCII (or ISO Latin-1) character.
// Browsers always URL-encode form values, so
// GetParameter method decodes automatically. But since
// We "re just passing this on to another server, we need
// 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 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,
"" + Message + "");
}



Public void doPost (HttpServletRequest request,
HttpServletResponse response)
Throws ServletException, IOException {
DoGet (request, response );
}
}

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.