九、处理Cookie
时间:2007-10-22 来源:不详 作者:林子
String searchString =
ServletUtilities.getCookieValue(cookies,
"searchString",
"Java Programming");
String numResults =
ServletUtilities.getCookieValue(cookies,
"numResults",
"10");
String searchEngine =
ServletUtilities.getCookieValue(cookies,
"searchEngine",
"google");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
String title = "Searching the Web";
out.println(ServletUtilities.headWithTitle(title)
"<BODY BGCOLOR=\"#FDF5E6\">\n"
"<H1 ALIGN=\"CENTER\">Searching the Web</H1>\n"
"\n"
"<FORM ACTION=\"/servlet/hall.CustomizedSearchEngines\">\n"
"<CENTER>\n"
"Search String:\n"
"<INPUT TYPE=\"TEXT\" NAME=\"searchString\"\n"
" VALUE=\"" searchString "\"><BR>\n"
"Results to Show Per Page:\n"
"<INPUT TYPE=\"TEXT\" NAME=\"numResults\"\n"
" VALUE=" numResults " SIZE=3><BR>\n"
"<INPUT TYPE=\"RADIO\" NAME=\"searchEngine\"\n" 内容来自dedecms
" VALUE=\"google\""
checked("google", searchEngine) ">\n"
"Google |\n"
"<INPUT TYPE=\"RADIO\" NAME=\"searchEngine\"\n"
" VALUE=\"infoseek\""
checked("infoseek", searchEngine) ">\n"
"Infoseek |\n"
"<INPUT TYPE=\"RADIO\" NAME=\"searchEngine\"\n"
" VALUE=\"lycos\""
checked("lycos", searchEngine) ">\n"
"Lycos |\n"
"<INPUT TYPE=\"RADIO\" NAME=\"searchEngine\"\n"
" VALUE=\"hotbot\""
checked("hotbot", searchEngine) ">\n"
"HotBot\n"
"<BR>\n"
"<INPUT TYPE=\"SUBMIT\" VALUE=\"Search\">\n"
"</CENTER>\n"
"</FORM>\n"
"\n"
"</BODY>\n"
"</HTML>\n");
}
private String checked(String name1, String name2) {
if (name1.equals(name2))
return(" CHECKED");
else
return("");
}
}
CustomizedSearchEngines.java
前面的SearchEnginesFrontEnd Servlet把数据发送到CustomizedSearchEngines Servlet。本例在许多方面与前面介绍HTTP状态代码时的例子相似,区别在于,本例除了要构造一个针对搜索引擎的URL并向用户发送一个重定向应答之外,还要发送保存用户数据的Cookies。

上一篇:十、会话状态 下一篇:八、设置HTTP应答头
文章评论
共有位Admini5网友发表了评论 查看完整内容