版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、我刚学 struts2 的时候,遇到很多这方面的问题。所以当我会了我决定把他们分享下来jsp 页面addnews.jsp 添加 all.jsp 信息显示 a href=delete.action?id=删除 a href=sid.action?id=更改该信息 分页查询 添加 fail.jsp insert title here fail 即将返回登陆页面 in.jsp insert title here index.jsp insert title here 现实新闻 login.jsp 登陆页面 用户名: 密码: login2-1.jsp insert title here ok.jsp
2、insert title here ok spage.jsp 分页查询显示 a href=deleteman.action?id=删除 a href=sidman.action?id=更改该信息 上一页 下一页 添加 updatenews.jsp 更新 编号为: 主体: 提交时间: 攥写人: 返回查询页面 实体 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; 连接数据库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) / 通过主键查询以更新string sql = select * from news where id= + id; system.out.println( 通过主键查询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( 已经删除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. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 《蔬菜品质与安全》课件
- 2025年萍乡货运从业资格证考试内容
- 《FX基础课程》课件
- 2025年安庆考从业资格证货运试题
- 金融服务学徒管理办法
- 惠州市工具租赁合同
- 美甲师岗位聘用协议书
- 生态修复区转让
- 珠宝店暖气管道维修施工合同
- 咨询公司业务技能培训
- 2024年室内设计协议书
- 中储粮西安分公司招聘真题
- 大学人工智能期末考试题库
- 2024土方开挖工程合同范本
- 建筑幕墙工程检测知识考试题库500题(含答案)
- 企业绿色供应链管理咨询服务合同
- 食品安全事故专项应急预案演练记录6篇汇编(表格式)
- 2025年会计基础知识考试题库附答案
- 《资治通鉴》导读学习通超星期末考试答案章节答案2024年
- 2024年统编版新教材语文小学一年级上册全册单元测试题及答案(共8单元)
- 企业年会的活动策划方案
评论
0/150
提交评论