日期:2014-05-16 浏览次数:21035 次
//创建XMLHTTPREQUEST组件
xmlHttp=createXmlHttpRequest();
//设置回调函数
xmlHttp.onreadystatechange=processRequest;
//打开与服务器响应地址的连接
xmlHttp.open("get","CheckUserServlet?uname="+uname,true);/////
//发送请求
xmlHttp.send(null);
public class CheckUserServlet extends HttpServlet {
private static final long serialVersionUID = -2105660521556754174L;
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
String user=request.getParameter("uname");
UserModel um=new UserModel();
response.setCharacterEncoding("utf-8");
PrintWriter out=response.getWriter();
//返回信息
out.print(um.validate(user));
out.flush();
out.close();
response.setContentType("text/html");
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 GET method");
out.println(" </BODY>");
out.println("</HTML>");
out.flush();
out.close();
}