当鼠标离开用户名输入框时,出发onblur事件,执行js函数,向处理程序传递用户名参数,处理程序向数据库中检索此参数(用户名)是否已经存在,并将相应结果反馈到页面中。向处理
处理程序部分
代码:
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
object ouname=context.Request["username"];
if (ouname == null)
{
context.Response.Write("cn-web提示:出错了!");
}
else
{
if (ouname.ToString() == "cn-web")//这里根据你的实际情况从数据库中检索数据
{
context.Response.Write("cn-
web提示:你的用户名已经存在!");
}
else
{
context.Response.Write("cn-web提示:您的用户名可以使用!");
}
}
}
js部分代码:
var serverAddress="OP.ashx";//要处理业务的页面地址
//messageID:要显示信息的div的id
//username:要验证的用户名
function getcommondata(messageID,username){
if (username){
username = encodeURIComponent(username);
document.getElementById(messageID).inner
HTML="
";
cache.push("username="+username);
}
if (cache.length > 0){
var cacheEntry = cache.shift();
getAJAX(cacheEntry,messageID);
}
}
Book.java
public class Book {
private int bid;
private String bname;
private String bauthor;
private String bpublisher;
private int cid;
private String binfo;
private float bprice;
public int getBid() {
return bid;
}
public void setBid(int bid) {
this.bid = bid;
}
public String getBname() {
return bname;
}
public void setBname(String bname) {
this.bname = bname;
}
public String getBauthor() {
return bauthor;
}
public void setBauthor(String bauthor) {
this.bauthor = bauthor;
}
public String getBpublisher() {
return bpublisher;
}
public void setBpublisher(String bpublisher) {
this.bpublisher = bpublisher;
}
public int getCid() {
return cid;
}
public void setCid(int cid) {
this.cid = cid;
}
public String getBinfo() {
return binfo;
}
public void setBinfo(String binfo) {
this.binfo = binfo;
}
public float getBprice() {
return bprice;
}
public void setBprice(float bprice) {
this.bprice = bprice;
}
public Book(int bid, String bname, String bauthor, String bpublisher,
int cid, String binfo, float bprice) {
super();
this.bid = bid;
this.bname = bname;
this.bauthor = bauthor;
this.bpublisher = bpublisher;
this.cid = cid;
this.binfo = binfo;
this.bprice = bprice;
}
public Book() {
super();
// TODO Auto-generated constructor stub
}
}
BookDao.java
public class BookDao {
//显示所有的书
public static Collection showBook(){
String sql="select * from tbl_book";
//连接数据库
Collection books=new ArrayList();
Connection conn=ConnDB.getConn();
Statement sta=null;
ResultSet rs=null;
try {
sta=conn.createStatement();
rs=sta.exec
uteQuery(
sql);
while(rs.next()){
int bid=rs.getInt(1);
String bname=rs.getString(2);
String bauthor=rs.getString(3);
String bpublisher=rs.getString(4);
int cid=rs.getInt(5);
String binfo=rs.getString(6);
float bprice=rs.getFloat(7);
Book book=new Book(bid,bname,bauthor,bpublisher,cid,binfo,bprice);
books.add(book);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
ConnDB.closeAll(rs, sta, conn);
return books;
}
}
}
分页实体
PageBean.java
public class PageBean {
//每一页显示的数据条数
int pageSize;
//页码
int pageNo;
//最大的页码
int maxPageNo;
//每一页显示的数据
ArrayList pageData=new ArrayList();
//总共的数据
ArrayList allData=new ArrayList();
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getPageNo() {
return pageNo;
}
public void setPageNo(int pageNo) {
t