版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)
文檔簡(jiǎn)介
1、我剛學(xué) struts2 的時(shí)候,遇到很多這方面的問(wèn)題。所以當(dāng)我會(huì)了我決定把他們分享下來(lái)jsp 頁(yè)面addnews.jsp 添加 all.jsp 信息顯示 a href=delete.action?id=刪除 a href=sid.action?id=更改該信息 分頁(yè)查詢 添加 fail.jsp insert title here fail 即將返回登陸頁(yè)面 in.jsp insert title here index.jsp insert title here 現(xiàn)實(shí)新聞 login.jsp 登陸頁(yè)面 用戶名: 密碼: login2-1.jsp insert title here ok.jsp
2、insert title here ok spage.jsp 分頁(yè)查詢顯示 a href=deleteman.action?id=刪除 a href=sidman.action?id=更改該信息 上一頁(yè) 下一頁(yè) 添加 updatenews.jsp 更新 編號(hào)為: 主體: 提交時(shí)間: 攥寫(xiě)人: 返回查詢頁(yè)面 實(shí)體 vo 包login.java package vo; public class login private string username; private string password; public string getusername() return username; pu
3、blic void setusername(string username) this.username = username; public string getpassword() return password; public void setpassword(string password) this.password = password; news.java package vo; public class news private int id; private int p; private string page; private string title; private s
4、tring body; private string addtime; private string addpeople; public int getp() return p; public void setp(int p) this.p = p; public string getpage() return page; public void setpage(string page) this.page = page; public int getid() return id; public void setid(int id) this.id = id; public string ge
5、ttitle() return title; public void settitle(string title) this.title = title; public string getbody() return body; public void setbody(string body) this.body = body; public string getaddtime() return addtime; public void setaddtime(string addtime) this.addtime = addtime; public string getaddpeople()
6、 return addpeople; public void setaddpeople(string addpeople) this.addpeople = addpeople; 連接數(shù)據(jù)庫(kù)dbcon.java package db; import java.sql.*; public class dbcon private connection conn = null; private statement stmt = null; private string dbdriver = com.mysql.jdbc.driver; private string dburl = jdbc:mysq
7、l:/localhost:3306/xx; private string dbuser = root; private string dbpass = dd; public dbcon() public connection getconnection() try class.forname(dbdriver); conn = drivermanager.getconnection(dburl, dbuser, dbpass); catch (classnotfoundexception e) / todo auto-generated catch block e.printstacktrac
8、e(); catch (sqlexception e) / todo auto-generated catch block e.printstacktrace(); return conn; public resultset do_query(string sql) resultset rs = null; conn = this.getconnection(); try stmt = conn.createstatement(); rs = stmt.executequery(sql); catch (sqlexception e) / todo auto-generated catch b
9、lock e.printstacktrace(); return rs; public int do_update(string sql) int res = 0; conn = this.getconnection(); try stmt = conn.createstatement(); res = stmt.executeupdate(sql); catch (sqlexception e) / todo auto-generated catch block e.printstacktrace(); return res; dao 包logindao.java package dao;
10、import java.util.arraylist; import java.util.list; import vo.login; import vo.news; import db.dbcon; public class logindao private dbcon db; private list result = new arraylist(); public logindao() db=new dbcon(); public list excute(string username,string password) string sql=select id,title from ne
11、ws where id=+username+ and title=+password+; return result; newsdao.java package dao; import java.sql.resultset; import java.sql.sqlexception; import java.util.arraylist; import java.util.list; import db.dbcon; import vo.news; public abstract class newsdao private dbcon db; private list result = new
12、 arraylist(); public newsdao() db = new dbcon(); public list spage(int pagesize,int nowpage) int count=0; int countpage; if(pagesize0&nowpage0) string sql0=select count(*) as pagecount from news; resultset rs0=db.do_query(sql0); try if(rs0.next() count=rs0.getint(pagecount); countpage=(count%pag
13、esize=0)?(count/pagesize):(count/pagesize+1); if(nowpagecountpage) nowpage=countpage; string sql=select * from news order by id limit +(nowpage*pagesize-pagesize)+,+pagesize; resultset rs=db.do_query(sql); try while(rs.next() news n = new news(); n.setid(rs.getint(id); n.settitle(rs.getstring(title)
14、; n.setbody(rs.getstring(body); n.setaddtime(rs.getstring(addtime); n.setaddpeople(rs.getstring(addpeople); result.add(n); catch (sqlexception e1) / todo auto-generated catch block e1.printstacktrace(); catch (sqlexception e) / todo auto-generated catch block e.printstacktrace(); return result; publ
15、ic list find_all() string sql = select * from news; resultset rs = db.do_query(sql); try while (rs.next() news n = new news(); n.setid(rs.getint(id); n.settitle(rs.getstring(title); n.setbody(rs.getstring(body); n.setaddtime(rs.getstring(addtime); n.setaddpeople(rs.getstring(addpeople); result.add(n
16、); catch (sqlexception e) / todo auto-generated catch block e.printstacktrace(); return result; public list sid(int id) / 通過(guò)主鍵查詢以更新string sql = select * from news where id= + id; system.out.println( 通過(guò)主鍵查詢id 為+id+ 的記錄 ); resultset rs = db.do_query(sql); try while (rs.next() news n = new news(); n.se
17、tid(rs.getint(id); n.settitle(rs.getstring(title); n.setbody(rs.getstring(body); n.setaddtime(rs.getstring(addtime); n.setaddpeople(rs.getstring(addpeople); result.add(n); catch (sqlexception e) / todo auto-generated catch block e.printstacktrace(); return result; public int delete(int id) int res =
18、 0; string sql = delete from news where id= + id; res = db.do_update(sql); system.out.print( 已經(jīng)刪除id 為+id+ 的記錄 ); return res; public int insert(news news) int res = 0; string sql = insert into news (id,title,body,addtime,addpeople) values (+ news.getid()+ ,+ news.gettitle() + ,+ news.getbody()+ ,+ ne
19、ws.getaddtime()+ ,+ news.getaddpeople() + ); res = db.do_update(sql); system.out.print(sql); return res; public int updatenews(news news) int res = 0; string sql =update news set title=+news.gettitle()+,body= +news.getbody()+,addtime=+news.getaddtime() +,addpeople=+news.getaddpeople()+where id=+news
20、.getid(); system.out.print(sql); res = db.do_update(sql); return res; action 類newsaction.java package action; import java.util.arraylist; import java.util.list; import com.opensymphony.xwork2.actionsupport; import vo.news; import dao.newsdao; public class newsaction extends actionsupport /* * */ pri
21、vate static final long serialversionuid = 1l; news news; private int id; private int nowpage=1; private int pagesize=5; private string uploadfile; public string getuploadfile() return uploadfile; public void setuploadfile(string uploadfile) this.uploadfile = uploadfile; public news getnews() return
22、news; public int getnowpage() return nowpage; public void setnowpage(int nowpage) this.nowpage = nowpage; public int getpagesize() return pagesize; public void setpagesize(int pagesize) this.pagesize = pagesize; public void setnews(news news) this.news = news; newsdao newsdao = new newsdao() ; priva
23、te list result = new arraylist(); public list getresult() return result; public void setresult(list result) this.result = result; public int getid() return id; public void setid(int id) this.id = id; public string find_all() result = newsdao.find_all(); return find_all; public string delete() newsdao.delete(id); system.out.print(id); return delete; public string insert() throws exception newsdao.insert(news); return insertall; public string updatenews() int res=newsdao.updatenews(news); if(res0) return su; else return fail; public string sid() result = n
溫馨提示
- 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 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ì)用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
- 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。
最新文檔
- 河邊公園救生員招聘合同
- 員工行為規(guī)范合同
- 信息技術(shù)安全員聘用合同
- 土地使用權(quán)權(quán)益變更協(xié)議書(shū)
- 農(nóng)業(yè)機(jī)械租賃終止合同
- 醫(yī)藥研發(fā)機(jī)構(gòu)藥師聘用協(xié)議
- 設(shè)計(jì)委托合同范本思考
- 設(shè)計(jì)公司創(chuàng)意總監(jiān)招聘合同
- 商場(chǎng)裝修專用升降機(jī)租賃服務(wù)協(xié)議
- 商場(chǎng)店鋪?zhàn)赓U合同
- 如何培養(yǎng)學(xué)生良好的雙姿習(xí)慣(精)
- 計(jì)算機(jī)及外部設(shè)備裝配調(diào)試員國(guó)家職業(yè)技能標(biāo)準(zhǔn)(2019年版)
- GB18613-2012中小型異步三相電動(dòng)機(jī)能效限定值及能效等級(jí)
- 《臨床決策分析》課件.ppt
- 家風(fēng)家訓(xùn)PPT課件
- 淚道沖洗PPT學(xué)習(xí)教案
- 淺談校園影視在學(xué)校教育中的作用
- 無(wú)公害農(nóng)產(chǎn)品查詢
- 試劑、試藥、試液的管理規(guī)程
- 研究生課程應(yīng)用電化學(xué)(課堂PPT)
- 通信綜合網(wǎng)管技術(shù)規(guī)格書(shū)doc
評(píng)論
0/150
提交評(píng)論