|
在jsp中用bean和servlet联合实现用户注册、登录(6) //System.out.println('\n' + myconn.rs_getHtmlString("name")); //System.out.println(myconn.rs.getString("name") + myconn.rs_getInt(1)); } }catch(Exception e){ System.err.println(e.toString()); } } }
声明:因为使用的是MySQL数据库,所以需要MySQL数据库的驱动 下载后请将org包放至DBConn.java所在目录下 以确保该bean能正常运行
三、编写用户注册的bean:reg.java
//reg.java
//import required classes import java.sql.*;
public class reg { public int newID = 0; public boolean result = false; public boolean reg(String username,String password,String confirm,String email) { try{ if(!this.checkUser(username)) return false; if(!this.checkPwd(password)) return false; if(!this.verifyPwd(password,confirm)) return false; if(!this.checkEmail(email)) return false; if(!this.userNotExit(username)) return false; this.getNewID(); this.result = this.register(username,password,confirm,email); return this.result; }catch(Exception e){ System.out.println(e.toString()); return false; } }//End boolean reg public boolean checkUser(String user) { try{ if(user.indexOf("'")!=-1) { System.out.println("姓名中含有非法字符!"); return false; }else return true; }catch(Exception e){ System.out.println(e.toString()); return false; } } public boolean checkPwd(String pwd) {
|