网上报名系统开发案例实训报告.docx
《网上报名系统开发案例实训报告.docx》由会员分享,可在线阅读,更多相关《网上报名系统开发案例实训报告.docx(25页珍藏版)》请在冰豆网上搜索。
网上报名系统开发案例实训报告
网上报名系统开发案例
三层架构设计与实现分为:
1.数据访问层
2.业务逻辑层
3.控制器
三个模块
(1).考生报名模块
(2).考生登录模块
(3).修改密码模块设计
package;
import.*;
import.*;
publicclassDBAccess{
privateConnectionconn=null;
privateStatementstmt=null;
privateResultSetrs=null;
privatePreparedStatementprpSql=null;
publicDBAccess(){}
/**
*返回一个数据库连接
*@returnConnection
*/
publicConnectiongetConn(){
if(conn==null){
getConnection();
}
returnconn;
}
/**
*加载MySQL驱动
*函数功能:
获得连接对象,Statement对象
*/
publicvoiddatabaseDriver()
{
try{("");
}
catch(Exceptione){}
}
publicvoidgetConnection(){
databaseDriver();
try{
conn=("jdbc:
","root","000000");
stmt=();;
import.*;
publicclassexamineeBll{
/**添加考生数据的方法**/
publicintCreateExaminee(StringexamID,String
examName,Stringsex,
Stringcompany,Stringaddress,String
phone,Stringemail,
Stringpassword,StringexamType,String
memo,Stringpic){
examineeDalexamDal=newexamineeDal();
intresult=0;
if(()==12||()==18)
&&()>0){
booleanisLD=true;
for(inti=0;i<();i++){
charc=(i);
if(!
((c<='z'&&c>='a')||(c<='Z')&&
(c>='A')||(c<='9')&&(c>='0'))){
isLD=false;
}
}
if(isLD==true&&
(examID)!
=null){
returnresult=-2;
}
if(isLD==true){
result=
(examID,examName,sex,company,address,phone,email,password,
examType,memo,pic);
}
}
else{
"身份证号或密码不符合要
求!
");
"函数返回值:
"+result);
}
returnresult;
}
/**考生登录方法***/
publicintexamineeLogin(StringexamID,Stringpassword){
examineeDalexamDal=newexamineeDal();
intresult=0;
if(()==12||()==18)
&&()>0){
examineeexam=null;
exam=(examID,
password);
if(exam!
=null){
result=1;
}
else{
result=-1;
}
}
returnresult;
}
/**储存照片文件名**/
publicintsetExamineePic(StringexamID,StringpicStr){
examineeDalexamDal=newexamineeDal();
repareStatement
(str);
(1,examID);
(2,password);
ResultSetrst=(prpSql);
if(rst!
=null&&()){
exam=newexaminee
(1),
(2),
(3),(4),(5),
(6),(7),(8),
(9),(10),(11)
);
}
if(prpSql!
=null){
();
prpSql=null;
}
}
}
catch(Exceptionne){
"examineedal:
getexamineebyIDPwd发生错误");
}
finally{
();
}
returnexam;
}
/**函数功能修改用户密码*@return成功返回1,否则返回*/
publicintsetExaminePwd(StringexamID,StringnewPassword){
DBAccessdba=newDBAccess();
intresult=0;
try{
if()!
=null){
PreparedStatementprpSql;
StringstrSql="Updateexamineeset
password=?
whereid=?
";
prpSql=().prepareStatement
(strSql);
(1,newPassword);
(2,examID);
result=(prpSql);
if(prpSql!
=null){
();
prpSql=null;
}
}
}catch(Exceptionne){
"exmaineedal:
setPassword发生
错误");
result=-1;
}
finally{
();
}
returnresult;
}
/**修改考生信息*@return影响行数,失败0*/
publicintupdateExamineeByID(StringexamID,String
examName,Stringsex,Stringcompany,Stringaddress,String
phone,Stringemail,StringexamType,Stringmemo){
DBAccessdba=newDBAccess();
intresult=0;
try{
if()!
=null){
PreparedStatementprpSql;
StringstrSql="updateexamineeset
name=?
sex=?
company=?
"+"address=?
phone=?
email=?
examType=?
memo
=?
whereid=?
";
prpSql=().prepareStatement
(strSql);
(1,examName);
(2,sex);
(3,company);
(4,address);
(5,phone);
(6,email);
(7,examType);
(8,memo);
(9,examID);
if(prpSql!
=null){
();
prpSql=null;
}
}
}
catch(Exceptionne){
();
return-1;
}
finally{
();
}
returnresult;
}
/**设置图片文件名*@paramexamID*@parampicStr*@return成功1,
失败0*/
publicintsetExamineePic(StringexamID,StringpicStr){
DBAccessdba=newDBAccess();
intresult=0;
try{
if()!
=null){
StringstrSql="updateexamineeset
pic='"+picStr+"'whereid='"+examID+"'";
result=(strSql);
}
}catch(Exceptionne){
"发生异常"+ne);
();
}
finally{
();
}
returnresult;
}
/**按身份证号删除考生*@paramexamID*@return1成功,0失败,出现异
常*/
publicintdeleteExmineeByID(StringexamID){
DBAccessdba=newDBAccess();
intresult=0;
try{
if()!
=null){
PreparedStatementprpSql;
StringstrSql="deletefromexaminee
whereid=?
";
prpSql=().prepareStatement
(strSql);
(1,examID);
result=();
if(prpSql!
=null){
();
prpSql=null;
}
}
}catch(Exceptionne){
();
return-1;
}
finally{
();
}
returnresult;
}
}
package;
import.*;
import.*;
import.*;
importclassHandleLoginextendsHttpServlet{
publicStringhandleString(Strings){
try{bytebb[]=("iso-8859-1");
s=newString(bb);
}catch(Exceptionee){}
returns;
}
publicHandleLogin(){
super();
}
/**
*Destructionoftheservlet.
*/
publicvoiddestroy(){
();
*
*Thismethodiscalledwhenaformhasitstagvalue
methodequalstoget.
*
*@paramrequesttherequestsendbytheclienttothe
server
*@paramresponsetheresponsesendbytheservertothe
client
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoGet(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException{
("text/html");
PrintWriterout=();
("
DOCTYPEHTMLPUBLIC\"-
*
*Thismethodiscalledwhenaformhasitstagvalue
methodequalstopost.
*
*@paramrequesttherequestsendbytheclienttothe
server
*@paramresponsetheresponsesendbytheservertothe
client
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoPost(HttpServletRequestrequest,
HttpServletResponseresponse)
throwsServletException,IOException{
loginBeanlog=null;
StringbackMessage="";
HttpSessionsession=(true);
try{
log=(loginBean)
("login");
if(log==null){
log=newloginBean();
("login",log);
}
}catch(Exceptionee){
log=newloginBean();
("login",log);}
StringloginName=
("loginName").trim(),
password=
("password").trim();
loginName=handleString(loginName);
booleanok=();
if(ok==true&&())){
backMessage="已经登录";
(backMessage);
}
else{
examineeBllexambll=newexamineeBll();
intresult=(loginName,
password);
if(result==1){
backMessage="登陆成功";
(backMessage);
(true);
(loginName);
}
elseif(result==0){
backMessage="您输入的身份证号或密码
不符合要求!
";
(backMessage);
(false);
(loginName);
(password);
}
else{
backMessage="您输入的身份证号不存在
或密码不正确!
";
(backMessage);
(false);
(loginName);
(password);
}
}
RequestDispatcher
dispatcher=("");
(request,response);
}
publicvoidinit(ServletConfigconfig)throws
ServletException{
();
}
}
package;
import.*;
import.*;
import.*;
importclassHandleModifPwdextendsHttpServlet{
/**
*Constructoroftheobject.
*/
publicHandleModifPwd(){
super();
}
/**
*Destructionoftheservlet.
*/
publicvoiddestroy(){
();
*
*Thismethodiscalledwhenaformhasitstagvaluemethodequalstoget.
*
*@paramrequesttherequestsendbytheclienttotheserver
*@paramresponsetheresponsesendbytheservertotheclient
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
doPost(request,response);
}
/**
*ThedoPostmethodoftheservlet.
*
*Thismethodiscalledwhenaformhasitstagvaluemethodequalstopost.
*
*@paramrequesttherequestsendbytheclienttotheserver
*@paramresponsetheresponsesendbytheservertotheclient
*@throwsServletExceptionifanerroroccurred
*@throwsIOExceptionifanerroroccurred
*/
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)
throwsServletException,IOException{
HttpSessionsession=(true);
loginBeanlog=(loginBean)("login");
if(log==null){
("");
}
else{
modifyPassword(request,response);
}
}
publicvoidmodifyPassword(HttpServletRequestrequest,
HttpServletResponseresponse)throwsServletException,IOException{
HttpSessionsession=(true);
loginBeanlog=(loginBean)("login");
StringloginName=();
passwordBeanpwd=newpasswordBean();
("password",pwd);
StringoldPassword=("oldPassword");
StringnewPassword=("newPassword");
examineeBllexambll=newexamineeBll();
intresult=(loginName,newPassword,oldPassword);
if(result==0){
("密码不符合要求,未更新!
");
}elseif(result==-1){
("旧密码不正确,密码更新失败!
");
}
else{
("更新成功!
");
(newPassword);
(oldPassword);
}
RequestDispatcherdispatcher=("");
(request,response);
}
/**
*Initializationoftheservlet.
*
*@throwsServletExceptionifanerroroccurs
*/
publicvoidinit(ServletConfigconfig)throwsServletException{
(config);
}
}
package;
import.*;
import.*;
importclassHandleRegisterextendsHttpServlet{
publicvoidinit(ServletConfigconfig)throwsServletException{
(config);
}
publicStringhandleString(Strings){
try{bytebb[]=("UTF-8");
s=newString(bb);
}
catch(Exceptionee){returns;
}
publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{
registerBeanreg=newregisterBean();
("register",reg);
StringexamID=("examID").trim(),
examName=("examName").trim(),
sex=("sex").trim(),
company=("company").trim(),
address=("address").trim(),
phone=("phone").trim(),
ema