版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領(lǐng)
文檔簡介
1、MVC作者:深藍王子SearchList.js p92期學(xué)員信息如<%string sql="select * from stude nt order by id"java.util.List list=sBea n.getSearch(sql;for(lterator it=list.iterator(;it.hasNext(;獲得JavaBean的一個對象jBea n=(com.jq92.bea n. JavaBea ni t. next(;%>%><%id姓名密碼性別年齡操作<%=jBea n.get<%=jBea n.getN&l
2、t;%=jBea n. get Pass<%=jBea n. get<%=jBea n. getmu 刪 除Id( %>ame( %>word( %>Sex( %>Age( %>更 新返回Id:v%=request.getAttnbute(" read only:姓名:v%=request.getAttnbute(":密碼:v%=request.getAttribute(":性別:o >男O >女年齡:v%=request.getAttribute(":V/S panxspan span更 v/spa
3、nxspan spanv/spanxspan sp aS>v/s panxspan span:v/s panxspan span重 v/spanxspan span: v/spanxspan sp aSH/s panxspan span:Up date.js p您要更新的數(shù)據(jù)如查詢Insert.js p92期學(xué)院管理頁面姓名:密碼:性別:O男O女年齡:v/s panxspan span提 v/spanxspan span> v/spanxspan sp ao>v/s panxspan span:v/s panxspan span重 v/spanxspan span> v
4、/spanxspan sp aS>v/s panxspan span:查詢Error.js p 對不起,您 v%=request.getAttribute("error" %失敗Servlet 部分Up date.javap ublic void doPo st(Htt pServletRequest request, Http ServletRes ponse res ponse throws ServletExce pti on, I OExce pti on /獲得前臺表單信息Stri ng sid=request.get Parameter("id&
5、quot;int id=In teger. parse In t(sid;String n ame=request.get Parameter" name"Stri ng p assword=request.get Parameter(” password"Stri ng sex=request.get Parameter("sex"String Sage=request.get Parameter("age"int age=In teger. parse In t(Sage;/圭寸裝到JavaBean對象中去JavaBea
6、 n jBea n=new JavaBea n(;jBea n. setId(id;jBea n. setName( name;jBea n. set Password( password;jBea n. setSex(sex;jBea n. setAge(age;String sql=" up date stude nt set n ame=?,p assword二?,sex二?,age=? where id=?"SqlBea n sBea n=new SqlBea n(;int coun t=sBea n. getU pdate(sql, jBea n;Stri ng
7、url=""if(cou nt>0 url="SearchList.js p"else url="Error.js p"request.setAttribute("error","更新"request.getRequestDis patcher(url.forward(request, res ponse;SearchByld.javap ublic void doPo st(Htt pServletRequest request, Http ServletRes ponse res po
8、nse throws ServletExce pti on, I OExce pti on /獲得idStri ng sid=request.get Parameter("id"int id=In teger. parse In t(sid;Stri ng sql="select * from stude nt where id=?"SqlBea n sBea n=new SqlBea n(;JavaBea n jBea n=sBea n. getSearchById(sql, id;/ID request.setAttribute("id&q
9、uot;, jBea n. getId(;/姓名 request.setAttribute(” name",jBea n.getName(;/密碼 request.setAttributeC' password", jBea n. get Password(;/性別String sex=""Stri ng man二""Stri ng woma n=""if(jBea n. getSex(!=null sex=jBea n. getSex(.trim(;if(sex.equals("男"
10、man="checked"else woma n="checked"request.setAttribute("ma n",ma n;request.setAttribute("woma n",woma n;/年齡 request.setAttribute("age", jBea n.getAge(;/轉(zhuǎn)發(fā) request.getRequestDis patcher("U pdate.js p".forward(request, res ponse;Insertjavap u
11、blic void doPo st(Htt pServletRequest request, Http ServletRes ponse res ponse throws ServletExce pti on, I OExce pti on /獲取前臺頁面信息 string n ame=request.get Parameter name"Stri ng p assword=request.get Parameter(” password"Stri ng sex=request.get Parameter("sex"String Sage=request
12、.get Parameter("age"int age=In teger. parse In t(Sage;/圭寸裝到JavaBean對象中 com.jq92.bea n. JavaBea n jBea n=new com.jq92.bea n. JavaBea n(;jBea n. setName( name;jBea n. set Password( password;jBea n. setSex(sex;jBea n. setAge(age;調(diào)用模型層Stri ng sql="i nsert into stude nt values(?,?,?,?"
13、;SqlBea n sBea n=new SqlBea n(;int coun t=sBea n. get In sert(sql, jBea n;Stri ng url=""if(cou nt>0 url="SearchList.js p"else url="Error.js p"request.setAttribute("error","注 冊"/轉(zhuǎn)發(fā) request.getRequestDis patcher(url.forward(request, res ponse;Delete
14、.javap ublic void doPo st(Htt pServletRequest request, Http ServletRes ponse res ponse throws ServletExce pti on, I OExce pti on /獲得刪除超鏈接傳來的參數(shù)Stri ng sld=request.get Parameter("id"int id=In teger. parse In t(sId;調(diào)用模型層刪除方法Stri ng sql="delete from stude nt where id=?"SqlBea n sBea
15、n=new SqlBea n(;int coun t=sBea n. getDelete(sql, id;Stri ng url=""if(cou nt>0 url="SearchList.js p"else url="Error.js p"request.setAttribute("error","刪除"request.getRequestDis patcher(url.forward(request, res ponse;JavaBea n.java p ackage com.jq92
16、.bea n;p ublic class JavaBea n p rivate int id;p rivate Stri ng n ame;p rivate Stri ng p assword;p rivate Stri ng sex;p rivate int age;p ublic int getAge( retur n age;p ublic void setAge(i nt age this.age = age;p ublic int getld( return id;p ublic void setId(i nt id this.id = id;p ublic String getNa
17、me( return n ame;p ublic void setName(Stri ng n ame this. name = n ame;p ublic String get Password( return p assword;p ublic void set Password(Stn ng p assword this .p assword = p assword;p ublic String getSex( retur n sex;p ublic void setSex(Stri ng sex this.sex = sex;SqlBea n.java p ackage com.jq9
18、2.bea n;import java.sql.C onn ectio n;import java.sql.DriverMa nager;import java.sql. Prep aredStateme nt;import java.sql.ResultSet;import java.sql.SQLExce ptio n;import java.util.ArrayList;import java.util.List;p ublic class SqlBea n Connection con;Prep aredStateme nt pre;ResultSet rs;p ublic SqlBe
19、a n( try Class.forNameC'com.microsoft.jdbc.sqlserver.SQLServerDriver" catch (ClassNotF oun dExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;try con=DnverMa nager.getC onn ectio n("jdbc:microsoft:sqlserver:/localhost:1433;Database Name=jq92Model2","sa","sa" c
20、atch (SQLExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;p ublic int getI nsert(Stn ng sqlJavaBea n jBea n int coun t=0;try p re=c on.prep areStateme nt(sql;p re.setStri ng(1,jBea n.getName(;p re.setStri ng(2,jBea n.get Password(;p re.setStri ng(3, jBea n. getSex(;p re.set In t(4, jBea n. getAge(
21、;count=p re.executeU pdate(; catch (SQLExce pti on e II TODO自動生成catch塊 e.prin tStackTrace(;fin ally try p re.close(;con. close(;catch (SQLExce pti on e II TODO自動生成catch塊 e.prin tStackTrace(;retur n count;p ublic int getDelete(Stri ng sql,i nt id int coun t=0;try p re=c on.prep areStateme nt(sql;p re
22、.setl nt(1, id;count=p re.executeU pdate(; catch (SQLExce pti on e II TODO自動生成catch塊 e.prin tStackTrace(;fin ally try p re.close(;con. close(;catch (SQLExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;retur n count;p ublic JavaBea n getSearchByld(Stn ng sql,i nt idJavaBea n jBea n=new JavaBea n(;t
23、ry p re=c on.prep areStateme nt(sql;p re.setI nt(1, id;rs=p re.executeQuery(;while(rs. next( jBea n.setld(rs.getl nt("id"jBea n.setName(rs.getStri ng(" name"jBea n.set Password(rs.getStri ng(" password"jBea n.setSex(rs.getStri ng("sex"jBea n.setAge(rs.getl nt(
24、"age" catch (SQLExce pti on e II TODO自動生成catch塊 e.prin tStackTrace(;retur n jBea n;p ublic int getU pdate(Stn ng sqlJavaBea n jBea n int coun t=0;try p re=c on.prep areStateme nt(sql;p re.setStri ng(1,jBea n.getName(;p re.setStri ng(2, jBea n.get Password(;p re.setStri ng(3, jBea n. getSex
25、(;p re.set In t(4, jBea n. getAge(;p re.setI nt(5, jBea n. getId(;count=p re.executeU pdate(; catch (SQLExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;fin ally try p re.close(;con. close(;catch (SQLExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;retur n count;p ublic List getSearch(Stn ng sql
26、List list=new ArrayList(;/獲得 prepareStatemen對象 try p re=c on.prep areStateme nt(sql;rs=p re.executeQuery(;while(rs. next(JavaBea n jBea n=new JavaBea n(;jBea n.setld(rs.getl nt("id"jBea n.setName(rs.getStri ng(" name"jBea n.set Password(rs.getStri ng(" password"jBea n.s
27、etSex(rs.getStri ng("sex"jBea n.setAge(rs.getl nt("age"list.add(jBea n; catch (SQLExce pti on e II TODO自動生成catch塊 e.prin tStackTrace(;fin ally try p re.close(;con. close(;catch (SQLExce pti on e / TODO自動生成catch塊 e.prin tStackTrace(;return list;Filter過濾器編碼轉(zhuǎn)換 p ackage com.jq92.filt
28、er;import java.io.IOExce pti on;import javax.servlet.Filter;import javax.servlet.FilterCha in;import javax.servlet.FilterC onfig;import javax.servlet.ServletExce pti on;import javax.servlet.ServletRequest;import javax.servlet.ServletRes ponse;p ublic class En cod in gFilter imp leme nts Filter Strin
29、g en cod in g=""p ublic void destroy( / TODO自動生成方法存根 p ublic void doFilter(ServletRequest request, ServletRes ponse res ponse.FilterChai n cha in throws IOExce pti on, ServletExce ptio n / TODO自動生成方法存根 request.setCharacterE ncodi ng(e ncodi ng;cha in. doFilter(request, res ponse;p ublic void in it(FilterC onfig config thro
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預(yù)覽,若沒有圖紙預(yù)覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時也不承擔(dān)用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 世界文化之旅-課件
- 《庫存管理與控制》課件
- 2024年鄉(xiāng)鎮(zhèn)計劃生育服務(wù)站工作總結(jié)
- 【課件】2024-2025學(xué)年上學(xué)期元旦主題班會課件
- 《項目管理》學(xué)習(xí)領(lǐng)域課程標(biāo)準(zhǔn)
- 第23課 內(nèi)戰(zhàn)爆發(fā)(解析版)
- 《設(shè)計過程質(zhì)量管理》課件
- 《生活安全指南》課件
- 化妝品行業(yè)促銷方案總結(jié)
- 2023-2024年項目部安全管理人員安全培訓(xùn)考試題【有一套】
- 微型頂管施工方案
- 湘教文藝版小學(xué)五年級音樂上冊期末測試題
- 老化箱點檢表A4版本
- 略說魯迅全集的五種版本
- 2022年110接警員業(yè)務(wù)測試題庫及答案
- 中聯(lián)16T吊車參數(shù)
- DB44∕T 115-2000 中央空調(diào)循環(huán)水及循環(huán)冷卻水水質(zhì)標(biāo)準(zhǔn)
- 嵌入式軟件架構(gòu)設(shè)計
- 《石油天然氣地質(zhì)與勘探》第3章儲集層和蓋層
- 航道整治課程設(shè)計--
- 超星爾雅學(xué)習(xí)通《科學(xué)計算與MATLAB語言》章節(jié)測試含答案
評論
0/150
提交評論