使用Ajax判断输入的用户名是否可用
2021-07-08 21:07
标签:pre utf-8 response text sed tchar for int exce JavaScript代码如下: HTML代码如下: //form表单 Servlet代码如下: package Servlet; import javax.servlet.ServletException; @Override @Override } 使用Ajax判断输入的用户名是否可用 标签:pre utf-8 response text sed tchar for int exce 原文地址:http://www.cnblogs.com/ybs1/p/7095632.html
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class UserServlet extends HttpServlet {
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();
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.setCharacterEncoding("UTF-8");
super.doPost(request, response);
}