1、javaeej2ee简单注册登录系统附详细源码1,布局如下2,所用数据库:mysql版.Drop table if exists user;CREATE TABLE user ( id int(10) unsigned NOT NULL auto_increment, username varchar(50) NOT NULL default , password varchar(10) default NULL, email varchar(50) default NULL, PRIMARY KEY (id), UNIQUE KEY ID (id), KEY ID_2 (id) ENGINE
2、=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=78 ;Insert into user values(10,shi,123,456);3.DBAccess.javapublic class DBAccess private String usr=root; private String pwd=; private Connection conn=null; private Statement stm=null; private ResultSet rs=null; public String getDrv() return drv; public vo
3、id setDrv(String drv) this.drv = drv; public String getUrl() return url; public void setUrl(String url) this.url = url; public String getUsr() return usr; public void setUsr(String usr) this.usr = usr; public String getPwd() return pwd; public void setPwd(String pwd) this.pwd = pwd; public Connectio
4、n getConn() return conn; public void setConn(Connection conn) this.conn = conn; return stm; public void setStm(Statement stm) this.stm = stm; return rs; public void setRs(ResultSet rs) this.rs = rs; /创建数据库连接函数 public boolean createConn() boolean b=false; try Class.forName(drv).newInstance(); conn=(C
5、onnection) DriverManager.getConnection(url,usr,pwd); b=true; catch(SQLException e) catch(ClassNotFoundException e) catch(InstantiationException e) catch(IllegalAccessException e) return b; /更新sql函数 public boolean update (String sql) boolean b=false; try stm=(Statement) conn.createStatement(); stm.ex
6、ecute(sql); b=true; catch(Exception e) return b; /查询sql函数 public void query (String sql) try stm=(Statement) conn.createStatement(); rs=(ResultSet) stm.executeQuery(sql); catch(Exception e) public boolean next() boolean b=false; try if(rs.next()b=true; catch(Exception e) return b; public String getV
7、alue(String field) String value=null; try if(rs!=null)value=rs.getString(field); catch(Exception e) return value; public void closeRs() try if(rs!=null) rs.close(); catch(SQLException e) public void closeStm() try if(rs!=null) stm.close(); catch(SQLException e) public void closeConn() try if(rs!=nul
8、l) conn.close(); catch(SQLException e) 4.UserBean.javapackagepublic class UserBean /登录验证函数 public boolean valid (String username, String password ) boolean isValid=false; DBAccess db=new DBAccess();if(db.createConn() String sql=select * from user where username=+username+and password=+password+; db.
9、query(sql); if(db.next() isValid=true; db.closeRs(); db.closeStm(); db.closeConn();return isValid;/检查用户名是否存在 public boolean isExist(String username) boolean isExist=false; DBAccess db=new DBAccess(); if(db.createConn() String sql=select * from user where username=+username+; db.query(sql); if(db.nex
10、t() isExist=true; db.closeRs(); db.closeStm(); db.closeConn(); return isExist; public void add(String username,String password,String email) DBAccess db=new DBAccess(); if(db.createConn() String sql=insert into user(username,password,email) values(+username+,+password+,+email+); db.update(sql); db.closeStm(); db.closeConn(); 5.login_action.jsp base href= My JSP login_action.jsp starting page 6.Login.jsp!DOCTYPE HTML PUBLIC -/W3C/DTD
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1