JSP課程設(shè)計(jì)論文(會(huì)員管理系統(tǒng))_第1頁(yè)
JSP課程設(shè)計(jì)論文(會(huì)員管理系統(tǒng))_第2頁(yè)
JSP課程設(shè)計(jì)論文(會(huì)員管理系統(tǒng))_第3頁(yè)
JSP課程設(shè)計(jì)論文(會(huì)員管理系統(tǒng))_第4頁(yè)
JSP課程設(shè)計(jì)論文(會(huì)員管理系統(tǒng))_第5頁(yè)
已閱讀5頁(yè),還剩25頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

實(shí)驗(yàn)報(bào)告(JSP課程設(shè)計(jì))班級(jí):14級(jí)計(jì)算機(jī)科學(xué)與技術(shù)01班學(xué)號(hào):141040200137姓名:許海峰目錄1.需求分析 31.1系統(tǒng)模塊設(shè)計(jì) 31.2數(shù)據(jù)庫(kù)設(shè)計(jì) 32.系統(tǒng)管理 42.1設(shè)計(jì)說(shuō)明 42.2頁(yè)面管理 42.3JavaBean與Servlet管理 42.4配置文件 43.會(huì)員注冊(cè) 63.1模型(Javabean) 63.2視圖(JSP頁(yè)面) 73.3 控制器(Servlet) 94.會(huì)員登錄 114.1模型(Javabean) 114.2視圖(JSP視圖) 124.3控制器(Servlet) 135.修改密碼 155.1模型(Javabean) 155.2視圖(JSP頁(yè)面) 165.3控制器(Servlet) 166.修改個(gè)人信息 186.1模型(Javabean) 186.2視圖(JSP頁(yè)面) 196.3控制器(Servlet) 206.3.1查詢(xún)注冊(cè)信息的Servlet 206.3.2修改注冊(cè)信息的Servlet 227.上傳照片 247.1模型(Javabean) 247.2視圖(JSP頁(yè)面) 257.3控制器(Servlet) 258.退出系統(tǒng) 299.設(shè)計(jì)總結(jié) 301.需求分析1.1系統(tǒng)模塊設(shè)計(jì) 本系統(tǒng)做為資源管理網(wǎng)站的一個(gè)子模塊,主要功能實(shí)現(xiàn)的功能是對(duì)于訪問(wèn)該網(wǎng)站的會(huì)員實(shí)行管理。 系統(tǒng)的主要模塊如下: ·會(huì)員注冊(cè)新會(huì)員要登錄該網(wǎng)站享有對(duì)該網(wǎng)站的資源進(jìn)行下載或者上傳資料就必須的有自己的會(huì)員號(hào)碼。會(huì)員在注冊(cè)的時(shí)候需要填寫(xiě)會(huì)員名、登錄密碼、E-mail地址等信息。如果該會(huì)員已經(jīng)存在與該系統(tǒng)的會(huì)員信息數(shù)據(jù)庫(kù)中,則提示注冊(cè)失敗。 ·會(huì)員登錄會(huì)員根據(jù)自己注冊(cè)的會(huì)員號(hào)碼和密碼登錄該系統(tǒng)。 ·修改會(huì)員資料如果會(huì)員的個(gè)人資料發(fā)生改變,可以對(duì)注冊(cè)時(shí)候的個(gè)人資料進(jìn)行修改。 ·修改密碼會(huì)員為了自己的信息的安全可以對(duì)自己的注冊(cè)時(shí)候填寫(xiě)的密碼進(jìn)行修改。 ·上傳照片為了方便會(huì)員的交流,會(huì)員在注冊(cè)之后可以修改自己的照片。1.2數(shù)據(jù)庫(kù)設(shè)計(jì) 本系統(tǒng)采用的加載純Java數(shù)據(jù)庫(kù)驅(qū)動(dòng)方式來(lái)方位數(shù)據(jù)庫(kù)。使用Access數(shù)據(jù)庫(kù)建立了一個(gè)shareresource數(shù)據(jù)庫(kù),該數(shù)據(jù)中建立一個(gè)userinfo表用來(lái)存儲(chǔ)會(huì)員的信息。 1.2.1userinfo表的字段 會(huì)員的注冊(cè)信息存入userinfo表中,userinfo的主鍵是loginid,標(biāo)準(zhǔn)的字段說(shuō)明如下: ·loginid會(huì)員登錄的帳號(hào)名字 ·password會(huì)員登錄的密碼 ·sex會(huì)員的性別 ·age會(huì)員的年齡 ·telphonenumber會(huì)員的電話號(hào)碼 ·email會(huì)員的電子郵件地址 ·message會(huì)員的個(gè)人簡(jiǎn)介 ·pic會(huì)員的照片,在注冊(cè)的時(shí)候會(huì)員默認(rèn)的照片是pic.jpg。 1.2.2userinfo的詳細(xì)設(shè)計(jì)如圖1-1所示 圖1-12.系統(tǒng)管理2.1設(shè)計(jì)說(shuō)明 本設(shè)計(jì)使用的JSP引擎是Tomcat6.0,使用Web目錄是share,share目錄安裝在Tomcat安裝目錄的webapps目錄下建立的web目錄。 在share目錄下建立目錄share\WEB-INF\classes然后建立子目錄mybean和myservlet兩個(gè)包,一個(gè)存放備案文件一個(gè)存放servlet文件。 連接數(shù)據(jù)庫(kù)使用的建立連接橋來(lái)連接數(shù)據(jù)庫(kù),因此在設(shè)計(jì)系統(tǒng)之前在本地?cái)?shù)據(jù)源新建share的系統(tǒng)數(shù)據(jù)源,方便實(shí)驗(yàn)Java連接數(shù)據(jù)庫(kù)。2.2頁(yè)面管理 本系統(tǒng)所有的JSP頁(yè)面都保存在share目錄中。 用戶(hù)可以通過(guò)在瀏覽器的地址欄中輸入http://服務(wù)器IP:9090/index.jsp來(lái)訪問(wèn)該主頁(yè)。2.3JavaBean與Servlet管理 本系統(tǒng)使用的Javabean的包名均為mybean;使用的servlet的包名均為myservlet,把通過(guò)編譯的Javabean類(lèi)和servlet類(lèi)分別存放在share\WEB-INF\classes\mybean和share\WEB-INF\classes\myservlet中。2.4配置文件 本系統(tǒng)使用的Servlet類(lèi)的包名均為myservlet,需要配置Web服務(wù)木蘭的web.xml文件。因此把寫(xiě)好的配置文件保存在share\WEB-INF中,配置文件的內(nèi)容如下:<?xmlversion="1.0"encoding="ISO-8859-1"?><web-app><servlet><servlet-name>procregister</servlet-name><servlet-class>cregister</servlet-class></servlet><servlet><servlet-name>proclogin</servlet-name><servlet-class>clogin</servlet-class></servlet><servlet><servlet-name>handleexit</servlet-name><servlet-class>myservlet.handleexit</servlet-class></servlet><servlet><servlet-name>handlepassword</servlet-name><servlet-class>myservlet.handlepassword</servlet-class></servlet><servlet><servlet-name>handlepersonal</servlet-name><servlet-class>myservlet.handlepersonal</servlet-class></servlet><servlet><servlet-name>changeInfo</servlet-name><servlet-class>myservlet.changeInfo</servlet-class></servlet><servlet><servlet-name>GetPersonalInfo</servlet-name><servlet-class>myservlet.GetPersonalInfo</servlet-class></servlet><servlet><servlet-name>HandleUpload</servlet-name><servlet-class>myservlet.HandlePicUpload</servlet-class></servlet><servlet-mapping><servlet-name>procregister</servlet-name><url-pattern>/procregister</url-pattern></servlet-mapping><servlet-mapping><servlet-name>proclogin</servlet-name><url-pattern>/proclogin</url-pattern></servlet-mapping><servlet-mapping><servlet-name>handleexit</servlet-name><url-pattern>/handleexit</url-pattern></servlet-mapping><servlet-mapping><servlet-name>handlepassword</servlet-name><url-pattern>/handlepassword</url-pattern></servlet-mapping><servlet-mapping><servlet-name>handlepersonal</servlet-name><url-pattern>/handlepersonal</url-pattern></servlet-mapping><servlet-mapping><servlet-name>changeInfo</servlet-name><url-pattern>/changeInfo</url-pattern></servlet-mapping><servlet-mapping><servlet-name>GetPersonalInfo</servlet-name><url-pattern>/GetPersonalInfo</url-pattern></servlet-mapping><servlet-mapping><servlet-name>HandleUpload</servlet-name><url-pattern>/HandleUpload</url-pattern></servlet-mapping></web-app>3.會(huì)員注冊(cè) 要登錄該網(wǎng)站就必須要有會(huì)員名,因此如果沒(méi)有成為會(huì)員的用戶(hù)必須注冊(cè)會(huì)員。在填寫(xiě)注冊(cè)信息的使用必須填寫(xiě)會(huì)員名,登錄密碼,以及基本的信息。3.1模型(Javabean) 描述注冊(cè)信息的Javabean中要有會(huì)員的名稱(chēng)、密碼、年齡、性別、郵箱、電話號(hào)碼以及一個(gè)注冊(cè)提示信息。 在register.java對(duì)這些信息進(jìn)行描述。具體代碼如下:packagemybean;publicclassregister{ Stringloginid,password,sex,phone,message,email,pic; Stringbacknews; intage; publicvoidsetLoginid(Stringid){ loginid=id; } publicStringgetLoginid(){ returnloginid; } publicvoidsetPassword(Stringpw){ password=pw; } publicStringgetPassword(){ returnpassword; } publicvoidsetSex(String_sex){ sex=_sex; } publicStringgetSex(){ returnsex; } publicvoidsetPhone(String_phone){ phone=_phone; } publicStringgetPhone(){ returnphone; } publicvoidsetMessage(Stringme){ message=me; } publicStringgetMessage(){ returnmessage; } publicvoidsetEmail(String_email){ email=_email; } publicStringgetEmail(){ returnemail; } publicvoidsetBacknews(String_backnews){ backnews=_backnews; } publicStringgetBacknews(){ returnbacknews; } publicvoidsetPic(String_pic){ pic=_pic; } publicStringgetPic(){ returnpic; } publicvoidsetAge(int_age){ age=_age; } publicintgetAge(){ returnage; }}3.2視圖(JSP頁(yè)面) 本模塊有兩個(gè)視圖,register.jsp與showRegisterInfo.jsp.一個(gè)提供用戶(hù)填寫(xiě)注冊(cè)信息,一個(gè)在用戶(hù)提供注冊(cè)信息之后返回是否注冊(cè)成功以及顯示注冊(cè)的信息。 注冊(cè)頁(yè)面的效果圖如圖3-1所示圖3-1 注冊(cè)成功之后的效果圖如圖3-2所示圖3-2 具體代碼代碼如下:Register.jsp<%@pagecontentType="text/html;charset=GBK"%><scriptlanguage="Javascript">functionon_submit(){ if(form.loginid.value==""){ alert("登錄賬號(hào)不能為空!"); form.loginid.focus(); returnfalse; } if(form.password.value==""){ alert("密碼不能為空"); form.userpw.focus(); returnfalse; } if(form.password.value.length<5){ alert("密碼至少5位"); form.userpw.focus(); returnfalse; } if(form.pw.value==""){ alert("校驗(yàn)密碼不能為空"); form.userpw1.focus(); returnfalse; } if(form.passwprd.value!=form.pw.value){ alert("兩次輸入密碼不同,請(qǐng)重新輸入"); form.userpw.focus(); returnfalse; } if(form.email.value==""){ alert("郵箱不能為空"); form.email.focus(); returnfalse; } if(form.email.value.indexOf("@")==-1){ alert("郵箱格式不正確!"); form.email.focus(); returnfalse; }}3.3 控制器(Servlet) Servlet負(fù)責(zé)連接數(shù)據(jù)庫(kù),以及把會(huì)員填寫(xiě)的基本信息寫(xiě)入userinfo表中,并且把會(huì)員信息轉(zhuǎn)發(fā)到showRegisterInfo.jsp頁(yè)面。 具體代碼如下:packagemyservlet;importmybean.*;importjava.sql.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclassprocregisterextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exceptione){ e.printStackTrace(); } } publicStringhandleString(Strings){ try{ bytebb[]=s.getBytes("iso-8859-1"); s=newString(bb); } catch(Exceptione1){ } returns; } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ response.setContentType("text/html;charset=GBK"); PrintWriterout=response.getWriter(); registerreg=newregister(); PreparedStatementsql; Connectioncon; request.setAttribute("register",reg); Stringloginid=request.getParameter("loginid").trim(); Stringpassword=request.getParameter("password").trim(); Stringsex=request.getParameter("sex").trim(); Stringemail=request.getParameter("email").trim(); Stringphone=request.getParameter("phone").trim(); Stringmessage=request.getParameter("message"); intage=Integer.parseInt(request.getParameter("age").trim()); Stringuri="jdbc:odbc:share"; booleanboo=loginid.length()>0&&password.length()>0; Stringbacknews=""; try{ con=DriverManager.getConnection("jdbc:odbc:share","",""); StringinsertCondition="insertintouserinfovalues(?,?,?,?,?,?,?,?)"; sql=con.prepareStatement(insertCondition); if(boo){ sql.setString(1,handleString(loginid)); sql.setString(2,handleString(password)); sql.setString(3,handleString(sex)); sql.setInt(4,age); sql.setString(5,phone); sql.setString(6,email); sql.setString(7,handleString(message)); sql.setString(8,"pic.jpg"); intm=sql.executeUpdate(); if(m!=0){ backnews="恭喜,注冊(cè)成功"; reg.setBacknews(backnews); reg.setLoginid(handleString(loginid)); reg.setPassword(handleString(password)); reg.setSex(handleString(sex)); reg.setAge(age); reg.setEmail(email); reg.setPhone(phone); reg.setMessage(handleString(message)); reg.setPic("pic.jpg"); } } else{ backnews="注冊(cè)失敗"; reg.setBacknews(backnews); } con.close(); } catch(SQLExceptione){ backnews="用戶(hù)已經(jīng)存在,請(qǐng)您重新注冊(cè)!"; reg.setBacknews(backnews); } RequestDispatcherdispatcher=request.getRequestDispatcher("/showregisterinfo.jsp");dispatcher.forward(request,response); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ doPost(request,response); }}4.會(huì)員登錄用戶(hù)在此頁(yè)面輸入自己的會(huì)員號(hào)、密碼登錄該網(wǎng)站,由于本設(shè)計(jì)只設(shè)計(jì)了會(huì)員管理系統(tǒng),模塊之中只有個(gè)人中心是有效模塊。會(huì)員進(jìn)行個(gè)人中心能進(jìn)行相關(guān)操作。4.1模型(Javabean) 模型login.java主要用來(lái)描述會(huì)員登錄時(shí)候的信息,其中包括會(huì)員號(hào)loginid、會(huì)員密碼password、已經(jīng)會(huì)員登錄狀態(tài)顯示issuccess以及顯示小時(shí)backnews。由于在下面的JSP頁(yè)面中都要顯示當(dāng)前的會(huì)員,因此在下面的頁(yè)面都要使用這個(gè)Javabean。代碼如下:packagemybean;publicclasslogin{ Stringloginid,password,backnews; booleanissuccess=false; publicvoidsetLoginid(Stringid){ loginid=id; } publicStringgetLoginid(){ returnloginid; } publicvoidsetPassword(Stringpw){ password=pw; } publicStringgetPassword(){ returnpassword; } publicvoidsetBacknews(Stringnews){ backnews=news; } publicStringgetBacknews(){ returnbacknews; } publicvoidsetSuccess(booleans){ issuccess=s; } publicbooleangetSuccess(){ returnissuccess; }}4.2視圖(JSP視圖) 本模塊有兩個(gè)個(gè)視圖:login.jsp提供給用戶(hù)填寫(xiě)登錄信息,如果會(huì)員號(hào)和密碼驗(yàn)證成功則進(jìn)入主頁(yè)面test.jsp。在主頁(yè)面提供給會(huì)員該網(wǎng)站的全部功能,從主頁(yè)面能夠進(jìn)入會(huì)員中心,會(huì)員中心能實(shí)現(xiàn)會(huì)員管理系統(tǒng)的全部功能。 登錄頁(yè)面的效果圖如圖4-1所示圖4-1 登錄成功之后顯示的主頁(yè)面效果圖如圖4-2所示 圖4-2從這個(gè)頁(yè)面進(jìn)入個(gè)人中心personal.jsp頁(yè)面。頁(yè)面效果如圖4-3所示:圖4-34.3控制器(Servlet) 控制器用于連接數(shù)據(jù)庫(kù),查詢(xún)會(huì)員填寫(xiě)的信息是否有效,驗(yàn)證密碼是否正確,并把會(huì)員信息發(fā)送到test.jsp頁(yè)面。具體代碼如下:packagemyservlet;importmybean.*;importjava.sql.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclassprocloginextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exceptione){} } publicStringhandleString(Strings){ try{ bytebb[]=s.getBytes("iso-8859-1"); s=newString(bb); } catch(Exceptione1){} returns; } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ response.setContentType("text/html;charset=GBK"); PrintWriterout=response.getWriter(); loginloginbean=null;; Connectioncon; //ResultSetrs; Stringuri="jdbc:odbc:share"; //Statementsql; Stringbacknews=""; HttpSessionsession=request.getSession(true); try{ loginbean=(login)session.getAttribute("login"); if(loginbean==null){ loginbean=newlogin(); session.setAttribute("login",loginbean); } } catch(Exceptionee){ loginbean=newlogin(); session.setAttribute("login",loginbean); } PreparedStatementsql; Stringloginid=request.getParameter("loginid").trim(); Stringpassword=request.getParameter("password").trim(); loginid=handleString(loginid); password=handleString(password); booleanok=loginbean.getSuccess(); if(ok==true&&loginid.equals(loginbean.getLoginid())){ backnews=loginid+"已經(jīng)登錄了"; loginbean.setBacknews(backnews); } else{ booleanboo=(loginid.length()>0)&&(password.length()>0); try{ con=DriverManager.getConnection(uri,"",""); Stringcondition="select*fromuserinfowhereloginid=?andpassword=?"; sql=con.prepareStatement(condition); if(boo){ sql.setString(1,loginid); sql.setString(2,password); ResultSetrs=sql.executeQuery(); if(rs.next()){ backnews="歡迎登錄"+loginid; loginbean.setBacknews(backnews); loginbean.setLoginid(loginid); loginbean.setSuccess(true); } else{ loginbean.setSuccess(false); backnews="帳號(hào)或者密碼錯(cuò)誤,請(qǐng)重新輸入!"; loginbean.setBacknews(backnews); } } else{ loginbean.setSuccess(false); backnews="帳號(hào)或者密碼錯(cuò)誤,請(qǐng)重新輸入!"; loginbean.setBacknews(backnews); } con.close(); } catch(SQLExceptione){} } RequestDispatcherdispatcher=request.getRequestDispatcher("/test.jsp");dispatcher.forward(request,response); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ doPost(request,response); }}5.修改密碼5.1模型(Javabean) Passwordbean.java主要來(lái)描述會(huì)員修改密碼是填寫(xiě)的信息。主要有:舊密碼oldpassword、新密碼newpassword以及提示信息backnews。具體代碼如下:packagemybean;publicclasspasswordbean{ Stringoldpasseord,newpassword,backnews; publicvoidsetOldpassword(String_oldpassword){ oldpasseord=_oldpassword; } publicStringgetOldpassword(){ returnoldpasseord; } publicvoidsetNewpassword(String_newpassword){ newpassword=_newpassword; } publicStringgetNewpassword(){ returnnewpassword; } publicvoidsetBacknews(String_backnews){ backnews=_backnews; } publicStringgetBacknews(){ returnbacknews; }}5.2視圖(JSP頁(yè)面) 本模塊有一個(gè)視圖:change_password.jsp提供用戶(hù)填寫(xiě)修改的舊密碼以及新密碼顯示密碼修改后的狀態(tài)。change_password.jsp的效果圖如5-1所示圖5-15.3控制器(Servlet) 控制器用來(lái)連接數(shù)據(jù)庫(kù)已經(jīng)修改userinfo表中的password字段的值。并能夠顯示修改成功與否和頁(yè)面的跳轉(zhuǎn)。具體代碼如下:Handlepassword.javapackagemyservlet;importmybean.*;importjava.sql.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclasshandlepasswordextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); } catch(Exceptione){} } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); booleanok=true; if(_login==null){ ok=false; response.sendRedirect("login.jsp"); } if(ok==true){ continueWork(request,response); } } publicvoidcontinueWork(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ response.setContentType("text/html;charset=GBK"); PrintWriterout=response.getWriter(); HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); Connectioncon=null; Stringloginid=_login.getLoginid(); passwordbean_passwordbean=newpasswordbean(); request.setAttribute("passwordbean",_passwordbean); StringoldPassword=request.getParameter("oldpassword"); StringnewPassword=request.getParameter("newpassword"); try{ con=DriverManager.getConnection("jdbc:odbc:share","",""); Statementsql=con.createStatement(); ResultSetrs=sql.executeQuery("SELECT*FROMuserinfowhereloginid='"+loginid+"'andpassword='"+oldPassword+"'"); if(rs.next()){ StringupdateString="UPDATEuserinfoSETpassword='"+newPassword+"'whereloginid='"+loginid+"'"; intm=sql.executeUpdate(updateString); if(m==1){ _passwordbean.setBacknews("密碼修改成功"); _passwordbean.setOldpassword(oldPassword); _passwordbean.setNewpassword(newPassword); out.print("<script>alert('密碼修改成功');location.href='personal.jsp'</script>"); } else{ out.print("<script>alert('密碼修改失敗');location.href='change_password.jsp'</script>"); _passwordbean.setBacknews("密碼修改失敗"); } } else{ out.print("<script>alert('密碼修改失敗');location.href='change_password.jsp'</script>"); _passwordbean.setBacknews("密碼修改失敗"); } con.close(); } catch(SQLExceptionexp){ out.print("<script>alert('修改成功')</script>"); _passwordbean.setBacknews("密碼修改失敗"+exp); } } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ doPost(request,response); }}6.修改個(gè)人信息6.1模型(Javabean) 模型中需要兩個(gè)Javabean,一個(gè)是前面注冊(cè)的register.java用來(lái)描述會(huì)員舊的注冊(cè)信息。一個(gè)是newInfo.java用來(lái)描述會(huì)員新的的信息。newInfo.java的代碼如下:packagemybean;publicclassnewInfo{Stringloginid,newSex,newEmail,newPhone,newMessage,backnews;intnewAge; publicvoidsetLoginid(String_loginid){ loginid=_loginid; } publicStringgetLoginid(){ returnloginid; } publicvoidsetNewSex(String_newSex){ newSex=_newSex; } publicStringgetNewSex(){ returnnewSex; } publicvoidsetNewEmail(String_newEmail){ newEmail=_newEmail; } publicStringgetNewEmail(){ returnnewEmail; } publicvoidsetNewPhone(String_newPhone){ newPhone=_newPhone; } publicStringgetNewPhone(){ returnnewPhone; } publicvoidsetNewMessage(String_newMessage){ newMessage=_newMessage; } publicStringgetNewMessage(){ returnnewMessage; } publicvoidsetBacknews(String_backnews){ backnews=_backnews; } publicStringgetBacknews(){ returnbacknews; } publicvoidsetNewAge(int_newAge){ newAge=_newAge; } publicintgetNewAge(){ returnnewAge; }}6.2視圖(JSP頁(yè)面)本模塊有3個(gè)JSP頁(yè)面:isChange.jsp、showinfo.jsp、change_personalinfo.jsp。在進(jìn)行個(gè)人信息修之前會(huì)員會(huì)選擇是否修改個(gè)人信息,如果選擇修改就進(jìn)行change_personalinfo.jsp頁(yè)面,該頁(yè)面會(huì)把會(huì)員注冊(cè)的信息顯示出來(lái)并提供會(huì)員修改。showinfo.jsp顯示會(huì)員修改之后的個(gè)人信息。isChange.jsp頁(yè)面的效果圖如圖6-1所示:圖6-1change_personalinfo.jsp的效果如圖6-2所示:圖6-2showinfo.jsp的效果如圖6-3所示:圖6-36.3控制器(Servlet)6.3.1查詢(xún)注冊(cè)信息的Servlet 該Servlet負(fù)責(zé)連接數(shù)據(jù)庫(kù),查詢(xún)userinfo表格,把當(dāng)前會(huì)員的個(gè)人信息轉(zhuǎn)發(fā)到change_personalinfo.jsp頁(yè)面。 Handlepersonal,javapackagemyservlet;importmybean.*;importjava.sql.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclasshandlepersonalextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun:jdbc:odbc:JdbcOdbcDriver"); } catch(Exceptione){} } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); booleanok=true; if(_login==null){ ok=false; response.sendRedirect("login.jsp"); } if(ok==true){ continueWork(request,response); } } publicvoidcontinueWork(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); Connectioncon=null; Stringloginid=_login.getLoginid(); register_register=newregister(); request.setAttribute("register",_register); try{ con=DriverManager.getConnection("jdbc:odbc:share","",""); Statementsql=con.createStatement(); ResultSetrs=sql.executeQuery("select*fromuserinfowhereloginid='"+loginid+"'"); if(rs.next()){ _register.setLoginid(rs.getString(1)); _register.setPassword(rs.getString(2)); _register.setSex(rs.getString(3)); _register.setAge(rs.getInt(4)); _register.setPhone(rs.getString(5)); _register.setEmail(rs.getString(6)); _register.setMessage(rs.getString(7)); _register.setPic(rs.getString(8)); _register.setBacknews("您注冊(cè)的信息如下:"); } con.close(); } catch(SQLExceptione){ _register.setBacknews(""+e); } RequestDispatcherdispatcher=request.getRequestDispatcher("/change_personalinfo.jsp"); dispatcher.forward(request,response); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ doPost(request,response); }}6.3.2修改注冊(cè)信息的Servlet 該Servlet負(fù)責(zé)連接數(shù)據(jù)庫(kù),將會(huì)員修改之后的信息寫(xiě)入userinfo表中,并將會(huì)員的信息轉(zhuǎn)發(fā)到受showInfo.jsp頁(yè)面。changeInfo,javapackagemyservlet;importmybean.*;importjava.io.*;importjava.sql.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclasschangeInfoextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun:jdbc:odbc:JdbcOdbcDriver"); } catch(Exceptione){} } publicStringhandleString(Strings){ try{ bytebb[]=s.getBytes("iso-8859-1"); s=newString(bb); } catch(Exceptionee){} returns; } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); booleanok=true; if(_login==null){ ok=false; response.sendRedirect("login.jsp"); } if(ok==true){ continueDoPost(request,response); } } publicvoidcontinueDoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); Stringloginid=_login.getLoginid(); Connectioncon; PreparedStatementsql; newInfo_newInfo=newnewInfo(); request.setAttribute("newInfo",_newInfo); Stringsex=request.getParameter("newSex").trim(), email=request.getParameter("newEmail").trim(), phone=request.getParameter("newPhone").trim(), message=request.getParameter("newMessage"); intage=Integer.parseInt(request.getParameter("newAge").trim()); StringbackNews=""; try{ con=DriverManager.getConnection("jdbc:odbc:share","",""); StringupdateCondition="UPDATEuserinfoSETsex=?,age=?,telphonenumber=?,email=?,message=?WHEREloginid=?"; sql=con.prepareStatement(updateCondition); sql.setString(1,handleString(sex)); sql.setInt(2,age); sql.setString(3,phone); sql.setString(4,handleString(email)); sql.setString(5,handleString(message)); sql.setString(6,loginid); intm=sql.executeUpdate(); if(m==1){ backNews="修改信息成功"; _newInfo.setBacknews(backNews); _newInfo.setLoginid(handleString(loginid)); _newInfo.setNewSex(handleString(sex)); _newInfo.setNewAge(age); _newInfo.setNewEmail(handleString(email)); _newInfo.setNewPhone(phone); _newInfo.setNewMessage(handleString(message)); } else{ backNews="信息填寫(xiě)不完整或信息中有非法字符"; _newInfo.setBacknews(backNews); } con.close(); } catch(SQLExceptionexp){ backNews="數(shù)據(jù)庫(kù)錯(cuò)誤!"+exp; _newInfo.setBacknews(backNews); } RequestDispatcherdispatcher=request.getRequestDispatcher("/shownewInfo.jsp"); dispatcher.forward(request,response); } publicvoiddoGet(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ doPost(request,response); }}7.上傳照片 用戶(hù)在注冊(cè)成會(huì)員之后可以上傳自己的照片,如果沒(méi)上傳照片,系統(tǒng)會(huì)提供一張默認(rèn)的照片給該會(huì)員。7.1模型(Javabean) Upload.java用來(lái)描述會(huì)員上傳的照片的信息。代碼如下:packagemybean;publicclassUploadPic{StringfileName,savedFileName,backNews="";publicvoidsetFileName(Stringname){fileName=name;}publicStringgetFileName(){returnfileName;}publicvoidsetSavedFileName(Stringname){savedFileName=name;}publicStringgetSavedFileName(){returnsavedFileName;}publicStringgetBackNews(){returnbackNews;}publicvoidsetBackNews(Strings){backNews=s;}}7.2視圖(JSP頁(yè)面) 本模塊有兩個(gè)JSP頁(yè)面,picupload.jsp提供用戶(hù)上傳照片,showUploadMess.jsp頁(yè)面顯示用戶(hù)上傳的照片信息。picupload.jsp的效果如圖7-1所示:圖7-1showUploadMess.jsp的效果如圖7-2所示:圖7-27.3控制器(Servlet) HandlePicUpload.java負(fù)責(zé)檢查會(huì)員是否登錄,連接數(shù)據(jù)庫(kù)以及修改數(shù)據(jù)庫(kù)中pic的字段。并且把會(huì)員上傳的照片保存到Share\image中,保存的照片名字為會(huì)員的帳號(hào)加上照片的名字。具體代碼如下:packagemyservlet;importmybean.*;importjava.sql.*;importjava.io.*;importjavax.servlet.*;importjavax.servlet.http.*;publicclassHandlePicUploadextendsHttpServlet{ publicvoidinit(ServletConfigconfig)throwsServletException{ super.init(config); try{ Class.forName("sun:jdbc:odbc:JdbcOdbcDriver"); } catch(Exceptione){} } publicvoiddoPost(HttpServletRequestrequest,HttpServletResponseresponse)throwsServletException,IOException{ HttpSessionsession=request.getSession(true); login_login=(login)session.getAttribute("login"); booleanok=true; if(_login==null){ ok=false; response.sendRedirect("login.jsp"); } if(ok==true){ Stringloginid=_login.getLoginid(); uploadFileMethod(request,response,loginid); } } publicvoiduploadFileMethod(HttpServletRequestrequest,HttpServletResponseresponse,Stringloginid)throwsServletException,IOException{ UploadPicupFile=newUploadPic(); StringbackNews=""; try{ HttpSessionsession=request.getSession(true); request.setAttribute("upFile",upFile); StringtempFileName=(String)session.getId(); Filef1=newFile(tempFileName); FileOutputStreamo=newFileOutputStream(f1); InputStreamin=request.getInputStream();byteb[]=newbyte[10000];intn;while((n=in.read(b))!=-1){ o.write(b,0,n); }o.close();in.close();RandomAccessFilerandom=newRandomAccessFile(f1,"r");intsecond=1;StringsecondLine=null;while(second<=2){ secondLine=random.readLine(); second++; }intposition=secondLine.lastIndexOf('\\');StringfileName=secondLine.substring(position+1,secondLine.length()-1);bytecc[]=fileName.getBytes("ISO-8859-1");fileName=newString(cc);fileName=fileName.replaceAll("","");StringsavedFileName=loginid.concat(fileName);random.seek(0);longforthEndPosition=0;intforth=1;while((n=random.readByte())!=-1&&(forth<=4)){ if(n=='\n'){ forthEndPosition=random.getFilePointer(); forth++; } }Filedir=newFile("D:\\Tomcat6.0\\webapps\\Share\\image");dir.mkdir();Filefile[]=dir.listFiles();for(intk=0;k<file.length;k++){ if(file[k].getName().startsWith(loginid)) file[k].delete();}FilesavingFile=newFile(dir,savedFileName);RandomAccessFilerandom2=newRandomAccessFile(savingFile,"rw");random.seek(random.length());

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論