|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
不得不提一下的是:.net是看到java红,而开发出来的工具。jspackagecoreservlets;
importjava.io.*;
importjavax.servlet.*;
importjavax.servlet.http.*;
importjava.net.*;
publicclassSearchEnginesextendsHttpServlet{
publicvoiddoGet(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException{
StringsearchString=request.getParameter("searchString");
if((searchString==null)||
(searchString.length()==0)){
reportProblem(response,"Missingsearchstring.");
return;
}
//TheURLEncoderchangesspacesto"+"signsandother
//non-alphanumericcharactersto"%XY",whereXYisthe
//hexvalueoftheASCII(orISOLatin-1)character.
//BrowsersalwaysURL-encodeformvalues,sothe
//getParametermethoddecodesautomatically.Butsince
//werejustpassingthisontoanotherserver,weneedto
//re-encodeit.
searchString=URLEncoder.encode(searchString);
StringnumResults=request.getParameter("numResults");
if((numResults==null)||
(numResults.equals("0"))||
(numResults.length()==0)){
numResults="10";
}
StringsearchEngine=
request.getParameter("searchEngine");
if(searchEngine==null){
reportProblem(response,"Missingsearchenginename.");
return;
}
SearchSpec[]commonSpecs=SearchSpec.getCommonSpecs();
for(inti=0;i<commonSpecs.length;i++){
SearchSpecsearchSpec=commonSpecs[i];
if(searchSpec.getName().equals(searchEngine)){
Stringurl=
searchSpec.makeURL(searchString,numResults);
response.sendRedirect(url);
return;
}
}
reportProblem(response,"Unrecognizedsearchengine.");
}
privatevoidreportProblem(HttpServletResponseresponse,
Stringmessage)
throwsIOException{
response.sendError(response.SC_NOT_FOUND,
"<H2>"+message+"</H2>");
}
publicvoiddoPost(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException{
doGet(request,response);
}
}
先谈谈我对java的一些认识。我选择java,是因为他语法简单,功能强大,从web,到桌面,到嵌入式,无所不能。但当我进一步了解了java后,感叹,java原来也有许多缺点。 |
|