資源描述:
《jsp注冊登錄頁面代碼》由會員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在行業(yè)資料-天天文庫。
1、jsp注冊頁面代碼用戶信息的bean:packagechen;publicclassUserBean{????????privateStringuserid;???????privateStringpassword;????????publicvoidsetUserId(Stringuserid)????????{????????????????this.userid=userid;????????}????????publicvoidsetPassword(Stringpassword)????????{???
2、?????????????this.password=password;????????}????????publicString??getUserId()????????{????????????????returnthis.userid;????????}????????publicStringgetPassword()????????{?????????????????returnthis.password;????????}}?提交數(shù)據(jù)庫的bean:packagechen;importcom.mysql.
3、jdbc.Driver;importjava.sql.*;publicclassUserRegister{????????privateUserBeanuserBean;????????privateConnectioncon;????????//獲得數(shù)據(jù)庫連接。????????publicUserRegister()????????{?????????????Stringurl="jdbc:mysql://localhost/"+"chao"+"?user="+"root"+"&password="+"8506
4、29";????????????try????????????{????????????????Class.forName("com.mysql.jdbc.Driver").newInstance();????????????????????????con=DriverManager.getConnection(url);????????????????}????????????????catch(Exceptione)????????????????{????????????????????????e.prin
5、tStackTrace();????????????????}????????}????????//設(shè)置待注冊的用戶信息。????????publicvoidsetUserBean(UserBeanuserBean)????????{????????????????this.userBean=userBean;????????}????????//進(jìn)行注冊????????publicvoidregist()throwsException????????{????????????????Stringreg="ins
6、ertintouserinfo(userid,password)??values(?,?)";????????????????try????????????????{????????????????????????PreparedStatementpstmt=con.prepareStatement(reg);????????????????????????pstmt.setString(1,userBean.getUserId());????????????????????????pstmt.setString
7、(2,userBean.getPassword());????????????????????????pstmt.executeUpdate();????????????????}????????????????catch(Exceptione)????????????????{????????????????????????e.printStackTrace();????????????????????????throwe;????????????????}????????}}提交注冊數(shù)據(jù)進(jìn)入數(shù)據(jù)庫:<%@pa
8、ge??contentType="text/html;charset=gb2312"pageEncoding="gb2312"?import="chen.*"%>