使用Ajax判断输入的用户名是否可用

2021-07-08 21:07

阅读:755

标签:pre   utf-8   response   text   sed   tchar   for   int   exce   

JavaScript代码如下:

HTML代码如下:

//form表单


//用户名文本框

用户名:

//显示是否可用消息的samp标签



Servlet代码如下:

package Servlet;
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 UserServlet extends HttpServlet {

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String name=request.getParameter("name");
boolean used=false;
if("ajax".equals(name)){
used=true;
}else{
used=false;
}
response.setContentType("text/html;charset=UTF-8");
PrintWriter out=response.getWriter();
out.print(used);
out.flush();
out.close();
}

@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
super.doPost(request, response);
}

}

使用Ajax判断输入的用户名是否可用

标签:pre   utf-8   response   text   sed   tchar   for   int   exce   

原文地址:http://www.cnblogs.com/ybs1/p/7095632.html


评论


亲,登录后才可以留言!