




版權說明:本文檔由用戶提供并上傳,收益歸屬內容提供方,若內容存在侵權,請進行舉報或認領
文檔簡介
實用文檔天津理工大學計算機科學與通信工程學院實驗報告2014 至 20 15 學年 第 一 學期課程名稱J2EE程序設計學號201XXXXX學生姓名XXX年級12級專業(yè)計算機科學教學班號02實驗地點7-216與技術實驗時間201X年XX月XX日第節(jié)至第節(jié)主講教師董玉濤輔導教師無文案大全計算機科學與通信工程學院實驗( 一 )軟件環(huán)境硬件環(huán)境實驗目的使用java的程序。
實驗名稱 用戶登錄處理Web程序A、實現(xiàn)語言J2EEB、環(huán)境要求:JDK1.4或以上MyEclipse8.5+TomCat5.0+JDKDocsSQLServer2000+W 系統(tǒng)32位機jsp及Servlet,結合jdbc制作一個簡單的用戶登錄處理 Web在登錄頁面中輸入正確的用戶名、密碼、確認密碼則可以正常登錄,并自動跳轉到歡迎頁面,并且在歡迎頁面中顯示當前所有已經(jīng)登錄的用戶名列表。數(shù)據(jù)庫中用戶名唯一。登錄錯誤則自動跳轉回到登錄頁面,并在登錄頁面中提示"登錄錯誤"。數(shù)據(jù)庫使用SQLServer2000+,數(shù)據(jù)庫字段及內容自行設計,頁面顯示方式自行設計。數(shù)據(jù)庫連接方式使用 jdbc-odbc 橋方式連接,也可以使用微軟提供的軟件包。提交內容為MyEclipse工程、數(shù)據(jù)庫備份文件(LoginDB.bak)以及針對本程序的使用說明簡述(readme.txt)。實驗內容(應包括實驗題目、實驗要求、實驗任務等)附錄(可包括源程序清單或其它說明)實驗源代碼如下:在eclipse 中新建項目如下:2計算機科學與通信工程學院截圖樣式登陸首頁注冊3計算機科學與通信工程學院登陸成功數(shù)據(jù)庫鏈接DBManager.javaimport import import 4計算機科學與通信工程學院public classDBManager{private static final String DBDRIVER ;privatestaticfinalStringDBNAME="performance5601";privatestaticfinalStringDBUSER="root";privatestaticfinalStringDBPASSWORD="123456";public static ConnectiongetConnection() throwsSQLException{Stringurl= + DBNAME+"?characterEncoding=utf-8" ;try {Class.forName(DBDRIVER);}catch(ClassNotFoundExceptione){e.printStackTrace();}return DriverManager. getConnection(url, DBUSER,DBPASSWORD);}}數(shù)據(jù)庫操作DaoOperation.javaimport import import import import import import public classDaoOperation{public static int insertData(Object...params) throwsSQLException{Stringsql= "insertintouser(username,password)values(?,?)" ;Connectionconn= null;PreparedStatementpreStmt= null;conn=DBManager.getConnection();preStmt=conn.prepareStatement(sql);setParams(preStmt,params);5計算機科學與通信工程學院int flag=preStmt.executeUpdate();if (preStmt!= null)preStmt.close();if (conn!= null)conn.close();return flag;}private static voidsetParams(PreparedStatement preStmt, Object... params)throwsSQLException{if (params== null ||params. length ==0)return ;for (int i=1;i<=params. length;i++){Objectparam=params[i-1];if (param== null){preStmt.setNull(i,Types. NULL);} else if (param instanceof Integer){preStmt.setInt(i,(Integer)param);} else if (param instanceof String){preStmt.setString(i,(String)param);}elseif(paraminstanceofDouble){preStmt.setDouble(i,(Double)param);}elseif(paraminstanceofLong){preStmt.setDouble(i,(Long)param);}elseif(paraminstanceofTimestamp){preStmt.setTimestamp(i,(Timestamp)param);}elseif(paraminstanceofBoolean){preStmt.setBoolean(i,(Boolean)param);}elseif(paraminstanceofDate){preStmt.setDate(i,(Date)param);}}}public static int UpdateInfo(Object...params) throwsSQLException{Stringsql= "updateusersetpassword=?" ;Connectionconn= null;PreparedStatementpreStmt= null;conn=DBManager.getConnection();preStmt=conn.prepareStatement(sql);setParams(preStmt,params);int num=preStmt.executeUpdate();6計算機科學與通信工程學院if (preStmt!= null)preStmt.close();if (conn!= null)conn.close();return num;}public static voiddelete( int stuId) throwsSQLException{Stringsql= "deletefromuserwhereusername=?" ;Connectionconn= null;PreparedStatementpreStmt= null;conn=DBManager.getConnection();preStmt=conn.prepareStatement(sql+stuId);preStmt.executeUpdate();if (preStmt!= null)preStmt.close();if (conn!= null)conn.close();return ;}public static Booleanselect(Stringusername,Stringpassword) throwsSQLException{Stringsql= "select*fromuserwhereusername=?andpassword=?" ;Connectionconn= null;PreparedStatementpreStmt= null;conn=DBManager.getConnection();preStmt=conn.prepareStatement(sql);preStmt.setString(1,username);preStmt.setString(2,password);ResultSetrs=preStmt.executeQuery();booleanflag= false ;while(rs.next()){flag= true ;}if (preStmt!= null)preStmt.close();if (conn!= null)conn.close();return flag;}7計算機科學與通信工程學院public static ResultSetselectALL() throwsSQLException{Stringsql= "select*fromuser" ;Connectionconn= null;PreparedStatementpreStmt= null;conn=DBManager.getConnection();preStmt=conn.prepareStatement(sql);ResultSetrs=preStmt.executeQuery();if (preStmt!= null)preStmt.close();if (conn!= null)conn.close();return rs;}}登陸查詢protected voiddoPost(HttpServletRequestrequest,HttpServletResponseresponse) throwsServletException,IOException{// TODOAuto-generatedmethodstubStringusername=request.getParameter( "username");Stringpassword=request.getParameter( "password1");Booleanflag= false;try {flag=DaoOperation. select(username,password);}catch(SQLExceptione){TODOAuto-generatedcatchblocke.printStackTrace();}if(flag){response.sendRedirect( "result.jsp" );}else{response.sendRedirect( "error.jsp" );}}注冊插入protected voiddoPost(HttpServletRequestrequest,HttpServletResponse8計算機科學與通信工程學院response) throwsServletException,IOException{TODOAuto-generatedmethodstubStringusername=request.getParameter( "username");Stringpassword1=request.getParameter( "password1");try {DaoOperation.insertData(username,password1);}catch(SQLExceptione){TODOAuto-generatedcatchblocke.printStackTrace();}response.sendRedirect( "index.jsp" );return ;}前臺HTML<!DOCTYPEhtml><html><head><title >登陸</title ><metahttp-equiv="keywords"content="keyword1,keyword2,keyword3"><metahttp-equiv="description"content="thisismypage"><metahttp-equiv=content=>"content-type""text/html;charset=UTF-8"<!--<linkrel="stylesheet"type="text/css"href="./styles.css">--></head><body><h1style="text-align:center">歡迎登陸</h1><divstyle="margin:auto;text-align:center"><formaction="login.d
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權益所有人同意不得將文件中的內容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內容本身不做任何修改或編輯,并不能對任何下載內容負責。
- 6. 下載文件中如有侵權或不適當內容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 年度工作計劃的涵蓋范圍與深度
- 學期課程安排的優(yōu)化計劃
- 長時間用眼下的視力保護技巧
- 提升團隊績效的年度目標設定計劃
- 加強學生自我表達能力的計劃
- 非手術治療中病人的疼痛管理與護理策略
- 面向未來的學校藝術教育-以綜合實踐活動為抓手
- 高效工作流如何在團隊中完成視頻剪輯與特效制作
- 跨部門協(xié)作與財務成本控制
- 購物中心會員忠誠度提升策略與案例分析
- 部編版八年級物理(上冊)期末試卷(帶答案)
- 《衡水內畫》課程標準
- DB32T 4400-2022《飲用水次氯酸鈉消毒技術規(guī)程》
- 化學品(氬氣+二氧化碳混合氣)安全技術使用說明書
- 煤層氣開發(fā)-第2章-煤層氣地質
- 美羅華(利妥昔單抗)課件
- 稅務簡易注銷課件
- 人教版五年級數(shù)學下冊第六單元分層作業(yè)設計
- 肺葉切除術和全肺切除術的麻醉課件
- 智能制造在食品加工業(yè)的應用
- BI軟件工程師個人年終工作總結
評論
0/150
提交評論