代码
<script src="jquery-1.4.2.min.js" type="text/javascript"></script>
<script language = "javascript">
function checkValue()
{
var buttonValue
= document.getElementById("textfield").value;
if(buttonValue.length == 0)
{
alert(
"输入不能为空!")
document.getElementById(
"textfield").focus();
}
else
{
if(buttonValue.length!=11)
{
alert(
"手机的位数应为11位!");
document.getElementById(
"textfield").value = "";
document.getElementById(
"textfield").focus();
}
else
{
$.ajax(
{
method:
"get",
url:
"./WebLogin",
data:
"buttonValue=" + buttonValue.toString(),
success:function(data)
{
if(data=="false")
{
alert(
"错误:您的手机号[" + buttonValue.toString() + "]未在系统中注册,无法执行重设密码功能。");
}
else
{
//提供更改密码服务
alert("准备更新密码,查收!");
}
}
});
}
}
}
</script>

以上是JS代码。

servlet代码:

 

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class validate extends HttpServlet
{
	public validate()
	{
		super();
	}
	public void doGet(HttpServletRequest request, HttpServletResponse response)
  throws ServletException, IOException
	{
		try
		{
			//response.setContentType("text/html");
			//PrintWriter out = response.getWriter();
			String value = request.getParameter("buttonValue");
			//out.println(value);
			Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
			java.sql.Connection connection = java.sql.DriverManager.getConnection("jdbc:odbc:local", "sa", "bhdc818");
			java.sql.Statement statement = connection.createStatement();
			String sql = "select * from dbo.hh_User where UserId = '" + value + "'";
			java.sql.ResultSet rs = statement.executeQuery(sql);
			if (rs.next())
				response.getWriter().write("true");
			else
				response.getWriter().write("false");
		}
		catch (Exception e)
		{
			e.printStackTrace();
		}
	}
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		this.doGet(request, response);
	}
}

xml代码:

 

代码
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns
="http://java.sun.com/xml/ns/javaee"
xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation
="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
>
<servlet>
<servlet-name>validate</servlet-name>
<servlet-class>validate</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>validate</servlet-name>
<url-pattern>/WebLogin</url-pattern>
</servlet-mapping>
</web-app>

 

附录:

工程目录下:

1.WEB-INF文件夹包括classes文件夹和web.xml!

2.修改完class要重启tomcat重新加载!

jsp代码:

 

<input type="button" value="重设密码" title="重设密码" onClick="checkValue()"/>
<input type="button" value="返回登陆页" title="返回" onClick="window.location.href='login.html';"/>