您好,欢迎访问三七文档
当前位置:首页 > 商业/管理/HR > 质量控制/管理 > 简单的学生信息管理系统
//连接数据库方法类JDBCConnection.javapackagegj;importjava.sql.Connection;importjava.sql.DriverManager;importjava.sql.SQLException;publicclassJDBCConnection{StringdriverName=com.mysql.jdbc.Driver;//驱动程序名StringuserName=root;//数据库用户名StringuserPwd=text;//密码StringdbName=user;//数据库名StringtableName=user_list3;//数据表名Stringurl=;publicStringgetDriverName(){returndriverName;}publicvoidsetDriverName(StringdriverName){this.driverName=driverName;}publicStringgetUserName(){returnuserName;}publicvoidsetUserName(StringuserName){this.userName=userName;}publicStringgetUserPwd(){returnuserPwd;}publicvoidsetUserPwd(StringuserPwd){this.userPwd=userPwd;}publicStringgetDbName(){returndbName;}publicvoidsetDbName(StringdbName){this.dbName=dbName;}publicStringgetTableName(){returntableName;}publicvoidsetTableName(StringtableName){this.tableName=tableName;}publicStringgetUrl(){returnurl;}publicvoidsetUrl(Stringurl){this.url=url;}//实现数据库连接的方法publicConnectiongetConnection()throwsSQLException,ClassNotFoundException{//实现数据库连接的方法Stringurl1=jdbc:mysql://localhost:3306/+dbName;Stringurl2=?user=+userName+&password=+userPwd;Stringurl3=&useUnicode=true&characterEncoding=GB2312;url=url1+url2+url3;Class.forName(driverName);returnDriverManager.getConnection(url);}}//用户登录界面Index.jspheadtitleMyJSP'index.jsp'startingpage/titlescripttype=text/javascriptfunctionvalidate(){varuserName=document.forms[form1].UserName.value;varpassword=document.forms[form1].pd.value;if(userName.length=0){alert(用户名不能为空!);}elseif(password=0){alert(密码不能为空!);}else{document.forms[form1].submit();}}/script/headbodybackground=img/4.jpgbrbrdivalign=lefth2用户登录/h2brbrformaction=CheckShowname=form1method=posttablewidth=248height=106border=0trtd用户名:/tdtdinputtype=textname=UserName//td/trtrtd密 码:/tdtdinputtype=passwordname=pd//td/trtrtdcolspan=2 inputtype=buttonvalue=登录onclick=validate()onmousemove=handahref=register.jspfontsize=2face=黑体注册/font/a inputtype=resetvalue=重置/td/tr/table/formp%=request.getAttribute(return)%/ppalign=left%intcount=0;if(application.getAttribute(count)==null){count+=1;application.setAttribute(count,count);}else{count=Integer.parseInt(application.getAttribute(count).toString());count+=1;application.setAttribute(count,count);}out.print(您是本系统的第+count+位访问者!);%/pp%=newDate()%/p/div/body/html//用户登录后台验证类CheckLogin.javapackagegj;importjava.sql.Connection;importjava.sql.ResultSet;importjava.sql.SQLException;importjava.sql.Statement;publicclassCheckLogin{privateStringname;privateStringpassword;publicStringgetName(){returnname;}publicvoidsetName(Stringname){this.name=name;}publicStringgetPassword(){returnpassword;}publicvoidsetPassword(Stringpassword){this.password=password;}publicCheckLogin(Stringname,Stringpassword){super();this.name=name;this.password=password;}publicintCheck()throwsSQLException,ClassNotFoundException{JDBCConnectionkkk=newJDBCConnection();Connectioncon=kkk.getConnection();Statementstatement;try{statement=con.createStatement();Stringsql=select*fromuser_list3wherename='+name+';ResultSetrs=statement.executeQuery(sql);ResultSetrs1=null;if(!rs.next()){return1;}else{Stringsql1=select*fromuser_list3wherepassword='+password+';rs1=statement.executeQuery(sql1);if(!rs1.next()){return2;}}rs.close();rs1.close();statement.close();con.close();}catch(Exceptione){e.printStackTrace();}return3;}}CheckLogin.java中dopost方法request.setCharacterEncoding(GB2312);Stringname=request.getParameter(UserName);Stringpd=request.getParameter(pd);CheckLogincl=newCheckLogin(name,pd);try{switch(cl.Check()){case1:request.setAttribute(return,用户名不存在!注册?);request.getRequestDispatcher(index.jsp).forward(request,response);break;case2:request.setAttribute(return,密码不存在!);request.getRequestDispatcher(index.jsp).forward(request,response);break;case3:request.getRequestDispatcher(main.jsp).forward(request,response);}}catch(SQLExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}catch(ClassNotFoundExceptione1){//TODOAuto-generatedcatchblocke1.printStackTrace();}//用户类packagegj.user;publicclassuser{privateStringUserName;privateStringpd;publicStringgetUserName(){returnUserName;}publicvoidsetUserName(StringuserName){UserName=userName;}publicStringgetPd(){returnpd;}publicvoidsetPd(Stringpd){this.pd=pd;}publicuser(StringuserName,Stringpd){super();UserName=userName;this.pd=pd;}}//用户注册界面Register.JsphtmlheadtitleMyJSP'register.jsp'startingpage/titlescripttype=text/javascriptfunctionfdate(){varuserName=document.forms[form2].name.value;varpassword=document.forms[form2].password.value;varrepassword=document.forms[form2].repassword.value;if(userName.length=0){alert(用户名不能为空!);}elseif(password=0){alert(密码不能为空!);}elseif(password!=repassword){alert(两次输入密码不一致!);}else{document.forms[form2].submit();}}/script/headbodybgcolor=#9999FFh2用户注册br/h2formaction=Registername=form2method=posttablewidth=242height=133border=0trtd
本文标题:简单的学生信息管理系统
链接地址:https://www.777doc.com/doc-6305486 .html