struts2解决登陆问题,struts解决分页问题,对mysql数据库的增删改查,配置文件的strutsxml的写法_第1页
struts2解决登陆问题,struts解决分页问题,对mysql数据库的增删改查,配置文件的strutsxml的写法_第2页
struts2解决登陆问题,struts解决分页问题,对mysql数据库的增删改查,配置文件的strutsxml的写法_第3页
struts2解决登陆问题,struts解决分页问题,对mysql数据库的增删改查,配置文件的strutsxml的写法_第4页
struts2解决登陆问题,struts解决分页问题,对mysql数据库的增删改查,配置文件的strutsxml的写法_第5页
已阅读5页,还剩12页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

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. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论