<%@ page language="java" import="java.util.*" pageEncoding="gb2312" %>
<%@ page import=" java.net.*" %> <html>
<head>
<script type="text/javascript">
function showHint(str)
{
var xmlhttp;
if (str.length==0)
{
document.getElementById("txtHint").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("txtHint").innerHTML=xmlhttp.responseText;
}
} xmlhttp.open("GET","servlet/gethint?q="+str,true);
xmlhttp.send();
}
</script>
<title>验证码测试</title>
</head>
<body>
<h3>请输入字母(a-z)</h3>
<form action="">
姓名:<input type="text" id="text1" onkeyup="showHint(this.value)"/>
<p>建议:<span id="txtHint"></span></p>
</form>
</body>
</html>
 package demoservlet;

 import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; public class gethint extends HttpServlet { /**
* Constructor of the object.
*/
public gethint() {
super();
} /**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("gb2312");
response.setCharacterEncoding("gb2312");
String str=request.getParameter("q"); response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.write("ada");
out.flush();
out.close();
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">");
out.println("<HTML>");
out.println(" <HEAD><TITLE>A Servlet</TITLE></HEAD>");
out.println(" <BODY>");
out.print(" This is ");
out.print(this.getClass());
out.println(", using the POST method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException {
// Put your code here
} }

最新文章

  1. 怎样制作FL Studio步进音序器中的节奏
  2. Ninject之旅之十一:Ninject动态工厂(附程序下载)
  3. 奶牛健美操(codevs 3279)
  4. [QualityCenter]设置工作流脚本-缺陷字段值发生变化时的处理
  5. [转]分布式文件系统FastDFS架构剖析
  6. mysql管理----状态参数释义
  7. maven -Dmaven.multiModuleProjectDirectory system propery is not set. Check $M2_HOME
  8. 使用 TestNG 测试的时候事务总是roll back的解决办法
  9. Python3基础系列——枚举类型大揭秘
  10. 使用Curator操作ZooKeeper
  11. hexo在github和coding.net部署并分流(一)
  12. Thread.Sleep(0)妙用
  13. 编译内核时出现__bad_udelay错误
  14. width:100%和width:auto区别
  15. javascript——后台传值map类型转换成json对象
  16. ORACLE AUDIT 审计
  17. python IDLE 自动提示功能
  18. C10K并发连接_转
  19. MyBatis 错误日志检索
  20. ansible命令使用

热门文章

  1. BrnShop开源网上商城第五讲:自定义视图引擎
  2. CCR源码分析-CCR架构
  3. tcxtreelist 控制单元格变颜色,或者行变颜色
  4. HDU 2647
  5. HDU 1953
  6. 【JS】Intermediate2:Events and Callbacks
  7. 类加载器classCloader
  8. leetcode&mdash;pascal triangle
  9. 最新Blog
  10. npm 国内镜像资源 --转载