SSH新闻发布系统
SQL:
prompt PL/SQL Developer import file
prompt Created on 2006年7月23日 by Administrator
set feedback off
set define off
prompt Creating ADMINUSER...
create table ADMINUSER
(
ID NVARCHAR2(30) not null,
NAME NVARCHAR2(50) not null,
PASSWORD NVARCHAR2(50) not null,
ADMINDATE NVARCHAR2(30),
AUTHOR NVARCHAR2(50),
DATE2 NVARCHAR2(50)
)
tablespace NJ01
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
alter table ADMINUSER
add constraint PK_ADMINUSER primary key (ID)
using index
tablespace NJ01
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
prompt Creating GUESTBOOK...
create table GUESTBOOK
(
ID NVARCHAR2(30) not null,
NAME NVARCHAR2(30) not null,
NEWID NVARCHAR2(30) not null,
GUESTDATE NVARCHAR2(50) not null,
DATE2 NVARCHAR2(50) not null,
GUESTCONTENT NVARCHAR2(300) not null,
IMAGE NVARCHAR2(50) not null
)
tablespace NJ01
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
alter table GUESTBOOK
add constraint PK_GUEST primary key (ID)
using index
tablespace NJ01
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
prompt Creating NEWS...
create table NEWS
(
ID NVARCHAR2(20) not null,
TYPEID NVARCHAR2(20) not null,
NEWTITLE NVARCHAR2(40) not null,
NEWAUTHOR NVARCHAR2(20) not null,
NEWFROM NVARCHAR2(20) not null,
NEWDATE NVARCHAR2(30) not null,
NEWCONTENT NVARCHAR2(400) not null,
COUNT NVARCHAR2(100),
DATE2 NVARCHAR2(100) not null
)
tablespace NJ01
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
alter table NEWS
add constraint PK_NEWS primary key (ID)
using index
tablespace NJ01
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
prompt Creating NEWTYPE...
create table NEWTYPE
(
ID NVARCHAR2(30) not null,
NEWTYPETITLE NVARCHAR2(50) not null,
TYPEAUTHOR NVARCHAR2(50) not null,
NEWTYPEDATE NVARCHAR2(50) not null,
DATE2 NVARCHAR2(50) not null
)
tablespace NJ01
pctfree 10
initrans 1
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
alter table NEWTYPE
add constraint PK_TYPE primary key (ID)
using index
tablespace NJ01
pctfree 10
initrans 2
maxtrans 255
storage
(
initial 64K
minextents 1
maxextents unlimited
);
prompt Disabling triggers for ADMINUSER...
alter table ADMINUSER disable all triggers;
prompt Disabling triggers for GUESTBOOK...
alter table GUESTBOOK disable all triggers;
prompt Disabling triggers for NEWS...
alter table NEWS disable all triggers;
prompt Disabling triggers for NEWTYPE...
alter table NEWTYPE disable all triggers;
prompt Deleting NEWTYPE...
delete from NEWTYPE;
commit;
prompt Deleting NEWS...
delete from NEWS;
commit;
prompt Deleting GUESTBOOK...
delete from GUESTBOOK;
commit;
prompt Deleting ADMINUSER...
delete from ADMINUSER;
commit;
prompt Loading ADMINUSER...
insert into ADMINUSER (ID, NAME, PASSWORD, ADMINDATE, AUTHOR, DATE2)
values ('9175930499', 'qzl', 'qzl', '2006-07-18 15:14', 'admin', '20060718151414');
insert into ADMINUSER (ID, NAME, PASSWORD, ADMINDATE, AUTHOR, DATE2)
values ('1106654074', 'juny', 'juny', '2006-07-18 14:58', 'admin', '20060718145813');
insert into ADMINUSER (ID, NAME, PASSWORD, ADMINDATE, AUTHOR, DATE2)
values ('3495385236', 'admin', 'admin', '2006-07-18 14:02', 'admin', '20060718140206');
insert into ADMINUSER (ID, NAME, PASSWORD, ADMINDATE, AUTHOR, DATE2)
values ('9605863242', '路人甲', '1', '2006-07-20 20:17', 'admin', '20060720201745');
insert into ADMINUSER (ID, NAME, PASSWORD, ADMINDATE, AUTHOR, DATE2)
values ('2199443025', '联通', '联通', '2006-07-20 20:26', '路人甲', '20060720202654');
commit;
prompt 5 records loaded
prompt Loading GUESTBOOK...
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('4869083904', '1t1t', '1111', '2006-07-22 21:07', '20060722210753', 'ddd', 'guestbookimage/face4.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1232948568', '1', '1111', '2006-07-21 21:12', '20060721211236', '111', 'guestbookimage/face2.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('8577339902', 'ss', '1111', '2006-07-21 22:01', '20060721220150', 'ss', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3935092975', 'w', '1111', '2006-07-21 22:24', '20060721222432', 'w', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('7007037004', 'aa', '1111', '2006-07-21 22:29', '20060721222902', 'aa', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('0796942977', 'r', '1111', '2006-07-22 00:10', '20060722001036', 'ww', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('4986423248', 'r', '1111', '2006-07-22 00:13', '20060722001345', 'ww', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3063690193', '1', '1111', '2006-07-22 00:18', '20060722001830', '1', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('4755785170', '1', '1111', '2006-07-22 00:20', '20060722002015', '1', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('5092498436', 'd', '1111', '2006-07-22 00:20', '20060722002037', 'd', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3121860529', 'd', '1111', '2006-07-22 00:21', '20060722002143', 'd', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1368517768', 's', '1111', '2006-07-22 00:22', '20060722002241', 's', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('6617698057', 's', '1111', '2006-07-22 00:23', '20060722002339', 's', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('5239324682', 'qq', '1111', '2006-07-22 00:26', '20060722002656', 'qq', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3465120388', 'qq', '1111', '2006-07-22 00:29', '20060722002925', 'qq', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('8107861701', '2', '1111', '2006-07-22 00:29', '20060722002957', '2', 'guestbookimage/face2.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('5327378515', '2', '1111', '2006-07-22 00:30', '20060722003009', '2', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1523134703', 'dd', '1111', '2006-07-23 14:55', '20060723145516', 'dd', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('0395471352', 'dd', '1111', '2006-07-23 14:59', '20060723145957', 'dd', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('9839303585', 'aa', '1111', '2006-07-23 15:11', '20060723151150', 'aa', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('6570902400', '1', '8969593665', '2006-07-23 15:12', '20060723151236', '11', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3099823056', '1', '8969593665', '2006-07-23 15:14', '20060723151410', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3620822771', '1', '8969593665', '2006-07-23 15:14', '20060723151414', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1959665858', '1', '8969593665', '2006-07-23 15:15', '20060723151510', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('8078321158', '1', '8969593665', '2006-07-23 15:15', '20060723151514', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('9318223197', '1', '8969593665', '2006-07-23 15:15', '20060723151517', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('2912503153', '1', '8969593665', '2006-07-23 15:15', '20060723151519', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('0121657820', '1', '8969593665', '2006-07-23 15:15', '20060723151521', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1921980341', '1', '8969593665', '2006-07-23 15:15', '20060723151524', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('6398839739', '1', '8969593665', '2006-07-23 15:15', '20060723151528', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3555620861', '1', '8969593665', '2006-07-23 15:16', '20060723151638', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('8187817015', '1', '8969593665', '2006-07-23 15:16', '20060723151642', '1', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('9796223804', '1', '1090064009', '2006-07-23 15:16', '20060723151654', '2', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3246738525', '1', '1090064009', '2006-07-23 15:16', '20060723151657', '2', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('0720273512', '4', '1090064009', '2006-07-23 15:17', '20060723151710', '4', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('4542458716', '5', '1090064009', '2006-07-23 15:17', '20060723151726', '5', 'image/face7.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('1972290061', 'd', '1090064009', '2006-07-23 15:18', '20060723151816', 'd', 'image/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('4365919654', 'd', '8969593665', '2006-07-23 15:19', '20060723151902', 'd', 'image/face2.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('3132824295', '33', '1111', '2006-07-21 23:58', '20060721235837', '333', 'guestbookimage/face1.gif');
insert into GUESTBOOK (ID, NAME, NEWID, GUESTDATE, DATE2, GUESTCONTENT, IMAGE)
values ('2876965783', 'ddd', '1111', '2006-07-23 14:59', '20060723145920', 'ddd', 'guestbookimage/face1.gif');
commit;
prompt 40 records loaded
prompt Loading NEWS...
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('1917013836', '8642130245', '2323', 'admin', '2332', '2006-07-20 20:05', '2323', '0', '20060720200534');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('6406259139', '8642130245', '99', 'admin', '99', '2006-07-20 20:04', '99', '1', '20060720200442');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('6630774636', '8642130245', 'rt', 'admin', 'rtr', '2006-07-20 20:03', 'trtrt', '0', '20060720200349');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('0572266284', '8642130245', '44', 'admin', '44', '2006-07-20 20:04', '44', '0', '20060720200424');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('4510504911', '8642130245', '77', 'admin', '7', '2006-07-20 20:04', '777', '1', '20060720200435');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('8969593665', '3817810373', 'JAVA发生7.2级地震', 'admin', 'sohu', '2006-07-19 14:36', 'JAVA发生7.2级地震', '13', '20060719143634');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('9528611282', '8642130245', 'juny', 'admin', 'junyj', '2006-07-18 17:55', 'uyny', '1', '20060718175523');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('3368987581', '8642130245', '66', 'admin', '66', '2006-07-20 20:04', '66', '1', '20060720200432');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('3622091730', '8642130245', '00', 'admin', '00', '2006-07-20 20:04', '00', '2', '20060720200446');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('1090064009', '8642130245', '1212', 'admin', '1212', '2006-07-20 20:05', '121', '2', '20060720200530');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('3093009522', '9662000923', 'll', 'juny', 'gggggg', '2006-07-18 14:59', 'll', '0', '20060718145937');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('5869043166', '8642130245', '55', 'admin', '55', '2006-07-20 20:04', '55', '0', '20060720200428');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('5002061104', '8642130245', 'ert', 'admin', 'ert', '2006-07-20 20:03', 'ert', '0', '20060720200343');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('5312247713', '8642130245', '34', 'admin', '34', '2006-07-20 20:04', '34', '0', '20060720200418');
insert into NEWS (ID, TYPEID, NEWTITLE, NEWAUTHOR, NEWFROM, NEWDATE, NEWCONTENT, COUNT, DATE2)
values ('4609500956', '8642130245', '88', 'admin', '88', '2006-07-20 20:04', '88', '2', '20060720200439');
commit;
prompt 15 records loaded
prompt Loading NEWTYPE...
insert into NEWTYPE (ID, NEWTYPETITLE, TYPEAUTHOR, NEWTYPEDATE, DATE2)
values ('8642130245', '体育新闻', 'admin', '2006-07-17 18:09', '20060717180941');
insert into NEWTYPE (ID, NEWTYPETITLE, TYPEAUTHOR, NEWTYPEDATE, DATE2)
values ('3817810373', 'IT风云', 'admin', '2006-07-17 22:55', '20060717225558');
commit;
prompt 2 records loaded
prompt Enabling triggers for ADMINUSER...
alter table ADMINUSER enable all triggers;
prompt Enabling triggers for GUESTBOOK...
alter table GUESTBOOK enable all triggers;
prompt Enabling triggers for NEWS...
alter table NEWS enable all triggers;
prompt Enabling triggers for NEWTYPE...
alter table NEWTYPE enable all triggers;
set feedback on
set define on
prompt Done.
---------------------------
接口: IAdminDao.java
package com.news.dao;
import com.news.struts.form.AddAdminForm;
public interface IAdminDao {
public void addAdmin(AddAdminForm addAdminForm);
public void deleteAdmin(AddAdminForm addAdminForm);
public void queryAdmin(AddAdminForm addAdminForm);
}
package com.news.dao;
import com.news.page.IpageGuestBookDao;
import com.news.struts.form.GuestForm;
public interface IguestBookDao extends IpageGuestBookDao{
public void add(GuestForm guestForm);
}
package com.news.dao;
import javax.servlet.http.HttpSession;
import com.news.struts.form.LoginForm;
public interface IloginDao {
public String validateUser(LoginForm loginForm,HttpSession s);
}
package com.news.dao;
import com.news.page.IpageNewsDao;
import com.news.struts.form.AddNewsForm;
public interface INewsDao extends IpageNewsDao {
public void insertNews(AddNewsForm addNewsForm);
public void findNews(AddNewsForm addNewsForm);
public void findNews2(AddNewsForm addNewsForm);
public void deleteNews(AddNewsForm addNewsForm);
public void changeNews(AddNewsForm addNewsForm);
public void change2News(AddNewsForm addNewsForm);
}
package com.news.dao;
import com.news.page.IpageDao;
import com.news.struts.form.AddtypeForm;
public interface ItypeDao extends IpageDao{
public void addType(AddtypeForm addtypeForm);
public void changeType(AddtypeForm addtypeForm);
public void changeFinType(AddtypeForm addtypeForm);
public void delType(AddtypeForm addtypeForm);
}
-----------------------
实现类:AdminDao.java
package com.news.dao.impl;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.Adminuser;
import com.news.dao.IAdminDao;
import com.news.struts.form.AddAdminForm;
import com.news.utils.GetDate;
import com.news.utils.GetId;
public class AdminDao extends HibernateDaoSupport implements IAdminDao{
public void addAdmin(AddAdminForm addAdminForm) {
Date d = new Date();
Adminuser user = new Adminuser();
user.setId(GetId.getId());
String name = addAdminForm.getName();
String hql = "from Adminuser where name = ?";
Session s = getHibernateTemplate().getSessionFactory().openSession();
Query q = s.createQuery(hql);
q.setParameter(0,name);
int n = q.list().size();
if(n>0){
name +=GetId.getNameId();
addAdminForm.setName(name);
}
s.close();
user.setName(name);
user.setPassword(addAdminForm.getPassword());
user.setAuthor(addAdminForm.getAuthor());
user.setAdmindate(GetDate.getDate1(d));
user.setDate2(GetDate.getDate2(d));
getHibernateTemplate().save(user);
}
public void deleteAdmin(AddAdminForm addAdminForm) {
Adminuser user= (Adminuser) getHibernateTemplate().load(Adminuser.class,addAdminForm.getId());
getHibernateTemplate().delete(user);
}
public void queryAdmin(AddAdminForm addAdminForm){
String hql = "from Adminuser order by date2 desc";
List adminlist = getHibernateTemplate().find(hql);
addAdminForm.setAdminlist(adminlist);
}
}
-----
package com.news.dao.impl;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.Guestbook;
import com.news.dao.IguestBookDao;
import com.news.page.Page;
import com.news.struts.form.GuestForm;
import com.news.utils.GetDate;
import com.news.utils.GetId;
public class GuestBookDao extends HibernateDaoSupport implements IguestBookDao{
public void add(GuestForm guestForm){
Guestbook guestbook = new Guestbook();
Date d = new Date();
guestbook.setId(GetId.getId());
guestbook.setName(guestForm.getName());
guestbook.setNewid(guestForm.getNewid());
guestbook.setGuestdate(GetDate.getDate1(d));
guestbook.setDate2(GetDate.getDate2(d));
guestbook.setGuestcontent(guestForm.getGuestcontent());
guestbook.setImage(guestForm.getImage());
getHibernateTemplate().save(guestbook);
}
public List getList(Page page,GuestForm guestForm){
final Page p = page;
final GuestForm form = guestForm;
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException, SQLException {
Query query = s.createQuery(p.getHql());
query.setParameter(0,form.getNewid());
query.setFirstResult(p.getStartRs());
query.setMaxResults(p.getPerPage());
List list = query.list();
return list;
}
});
}
public int getTotal(String hql,GuestForm guestForm){
//System.out.println("sss");
Session s = getHibernateTemplate().getSessionFactory().openSession();
Query q = s.createQuery(hql);
q.setParameter(0,guestForm.getNewid());
List result = q.list();
s.close();
if (null != result && !result.isEmpty()) {
return (result.size());
} else {
return 0;
}
}
}
----
package com.news.dao.impl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.dao.IintoViewDao;
import com.news.page.Page;
import com.news.struts.form.IntoViewForm;
public class IntoViewDao extends HibernateDaoSupport implements IintoViewDao{
public List getList(Page page,IntoViewForm intoViewForm){
final Page p = page;
final IntoViewForm form = intoViewForm;
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException, SQLException {
Query query = s.createQuery(p.getHql());
query.setParameter(0,form.getTypeid());
query.setFirstResult(p.getStartRs());
query.setMaxResults(p.getPerPage());
List list = query.list();
return list;
}
});
}
public int getTotal(String hql,IntoViewForm intoViewForm){
//System.out.println("sss");
Session s = getHibernateTemplate().getSessionFactory().openSession();
Query q = s.createQuery(hql);
q.setParameter(0,intoViewForm.getTypeid());
List result = q.list();
getHibernateTemplate().getSessionFactory().close();
if (null != result && !result.isEmpty()) {
return (result.size());
} else {
return 0;
}
}
}
package com.news.dao.impl;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpSession;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.Adminuser;
import com.news.dao.IloginDao;
import com.news.struts.form.LoginForm;
public class LoginDao extends HibernateDaoSupport implements IloginDao{
public String validateUser(LoginForm loginForm,HttpSession s){
String str ;
String name = loginForm.getName();
String pwd = loginForm.getPassword();
String hql = "from Adminuser where name = ? and password = ?";
String rand = (String) s.getAttribute("rand");
Session hibs = getHibernateTemplate().getSessionFactory().openSession();
Query q = hibs.createQuery(hql);
q.setParameter(0,name);
q.setParameter(1,pwd);
List list = q.list();
if(list.size()<=0){
str = "faile";
return str;
}
if(!loginForm.getRandInput().equals(rand)||loginForm.getRandInput()==null||loginForm.getRandInput().equals("")){
str = "faile";
loginForm.setRandInput(null);
return str;
}
str = "typeok";
List adminList = new ArrayList();
for(int i=0;i<LIST.SIZE();I++){ pre < } str; return hibs.close(); s.removeAttribute(?rand?); s.setAttribute(?admin?,adminList); adminList.add(admin); list.get(i); admin="(Adminuser)" Adminuser>
<SCRIPT src="/inc/gg_read2.js"></SCRIPT>
----------
package com.news.dao.impl;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.News;
import com.news.dao.IlookDao;
import com.news.struts.form.LookForm;
public class LookDao extends HibernateDaoSupport implements IlookDao {
public void look(LookForm lookForm){
News news = (News) getHibernateTemplate().load(News.class,lookForm.getId());
lookForm.setNewtitle(news.getNewtitle());
lookForm.setNewfrom(news.getNewfrom());
lookForm.setNewcontent(news.getNewcontent());
lookForm.setNewauthor(news.getNewauthor());
int count = Integer.parseInt(news.getCount());
//System.out.println(count);
count +=1;
//System.out.println(count);
String c = String.valueOf(count);
//System.out.println(c);
news.setCount(c);
getHibernateTemplate().save(news);
}
}
-----
-
package com.news.dao.impl;
import java.sql.SQLException;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.dao.IsearchDao;
import com.news.struts.form.SearchForm;
public class SearchDao extends HibernateDaoSupport implements IsearchDao {
public void search(SearchForm searchForm){
//System.out.println(searchForm.getNewtitle());
final SearchForm search = searchForm;
List searchlist = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException, SQLException {
//String hql = "from News where newtitle = ? order by date2 desc";
String hql = "from News where newtitle like ? order by date2 desc";
Query q = s.createQuery(hql);
q.setParameter(0,"%"+search.getNewtitle()+"%");
return q.list();
}
});
searchForm.setSearchList(searchlist);
}
}
---------------
package com.news.dao.impl;
import java.sql.SQLException;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.hibernate.classic.Session;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.Newtype;
import com.news.dao.ItypeDao;
import com.news.page.Page;
import com.news.struts.form.AddtypeForm;
import com.news.utils.GetDate;
import com.news.utils.GetId;
public class TypeDao extends HibernateDaoSupport implements ItypeDao{
/**
* 增加新的新闻种类
*/
public void addType(AddtypeForm addtypeForm){
Newtype newtype = new Newtype();
Date d = new Date();
newtype.setId(GetId.getId());
newtype.setNewtypetitle(addtypeForm.getNewtypetitle());
newtype.setTypeauthor(addtypeForm.getTypeauthor());
newtype.setNewtypedate(GetDate.getDate1(d));
newtype.setDate2(GetDate.getDate2(d));
getHibernateTemplate().save(newtype);
}
/**
* 修改新闻种类
*/
public void changeType(AddtypeForm addtypeForm){
String id = addtypeForm.getId();
Newtype newtype = (Newtype) getHibernateTemplate().load(Newtype.class,id);
addtypeForm.setId(newtype.getId());
addtypeForm.setNewtypetitle(newtype.getNewtypetitle());
addtypeForm.setTypeauthor(newtype.getTypeauthor());
}
/**
* 修改新闻种类完成
*/
public void changeFinType(AddtypeForm addtypeForm){
String id = addtypeForm.getId();
Newtype newtype = (Newtype) getHibernateTemplate().load(Newtype.class,id);
newtype.setNewtypetitle(addtypeForm.getNewtypetitle());
//newtype.setTypeauthor(addtypeForm.getTypeauthor());
getHibernateTemplate().save(newtype);
}
/**
* 删除新闻种类 删除种类的同时删除他的相关新闻
*/
public void delType(AddtypeForm addtypeForm){
final String id = addtypeForm.getId();
Newtype newtype = (Newtype)getHibernateTemplate().load(Newtype.class,id);
String hql = "from News where typeid = ?";
Session s = getHibernateTemplate().getSessionFactory().openSession();
Query q = s.createQuery(hql);
q.setParameter(0,id);
List list = q.list();
s.close();
getHibernateTemplate().delete(newtype);
getHibernateTemplate().deleteAll(list);
}
/**
* 用于分页的查询
*/
public List getList(Page page){
final Page p = page;
return getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException, SQLException {
Query query = s.createQuery(p.getHql());
query.setFirstResult(p.getStartRs());
query.setMaxResults(p.getPerPage());
List list = query.list();
return list;
}
});
}
public int getTotal(String hql) {
List result = getHibernateTemplate().find(hql);
if (null != result && !result.isEmpty()) {
return ((Integer) result.get(0)).intValue();
} else {
return 0;
}
}
}
------------------
package com.news.dao.impl;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import org.hibernate.Query;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import com.news.bean.News;
import com.news.dao.IviewDao;
import com.news.struts.form.ViewForm;
import com.news.utils.GetDate;
public class ViewDao extends HibernateDaoSupport implements IviewDao {
public void query(ViewForm viewForm){
String hql = "from Newtype order by date2 desc";
List typelist = getHibernateTemplate().find(hql);
viewForm.setViewList(typelist);
}
public void queryNews(ViewForm viewForm){
final ViewForm view = viewForm;
List newslist = getHibernateTemplate().executeFind(new HibernateCallback() {
public Object doInHibernate(org.hibernate.Session s) throws org.hibernate.HibernateException, SQLException {
String hql = "from News where typeid = ? order by date2 desc";
Query q = s.createQuery(hql);
q.setParameter(0,view.getTypeid());
q.setFirstResult(0);
q.setMaxResults(8);
return q.list();
}
});
List list = new ArrayList();
long time1 = new Long(GetDate.getDate2(new Date())).longValue();
for(int i=0;i<NEWSLIST.SIZE();I++){ pre < } viewForm.setNewsList(list); list.add(viewform); viewform.setFirstNews(img); ; img="<img src='image/firstnew.gif' align='absbottom' border='0'>" String }else{ if(time<="1000000){" System.out.println(time); time="time1-time2;" long Long(news.getDate2()).longValue(); time2="new" viewform.setTypeid(news.getTypeid()); viewform.setNewtitle(news.getNewtitle()); viewform.setNewsid(news.getId()); newslist.get(i); news="(News)" News ViewForm(); viewform="new" ViewForm>
<SCRIPT src="/inc/gg_read2.js"></SCRIPT>
-----------------------
控制器:action
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import com.news.service.IAdminService;
import com.news.struts.form.AddAdminForm;
import com.news.utils.GetXml;
import com.news.valsession.AdminValsession;
public class AddAdminAction extends DispatchAction {
public ActionForward add(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddAdminForm addAdminForm = (AddAdminForm) form;
BeanFactory factory = GetXml.getXml();
IAdminService admin = (IAdminService) factory.getBean("userinfoServiceAdmin");
AdminValsession a = new AdminValsession();
String url = a.valid(request,addAdminForm);
if(!url.equals("faile")&&!url.equals("addfaile")){
admin.addAdmin(addAdminForm);
url = "addok";
}
System.out.println(url);
return mapping.findForward(url);
}
public ActionForward query(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddAdminForm addAdminForm = (AddAdminForm) form;
BeanFactory factory = GetXml.getXml();
IAdminService admin = (IAdminService) factory.getBean("userinfoServiceAdmin");
AdminValsession a = new AdminValsession();
String url = a.valid(request,addAdminForm);
if(url.equals("ok")){
admin.queryAdmin(addAdminForm);
url = "return";
}
return mapping.findForward(url);
}
public ActionForward del(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddAdminForm addAdminForm = (AddAdminForm) form;
BeanFactory factory = GetXml.getXml();
IAdminService admin = (IAdminService) factory.getBean("userinfoServiceAdmin");
AdminValsession a = new AdminValsession();
String url = a.valid(request,addAdminForm);
if(!url.equals("faile")){
admin.deleteAdmin(addAdminForm);
}
return mapping.findForward("ok");
}
}
-----------
package com.news.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import com.news.service.INewsService;
import com.news.struts.form.AddNewsForm;
import com.news.utils.GetXml;
import com.news.valsession.NewsValsession;
public class AddNewsAction extends DispatchAction {
public ActionForward add(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
String typeid = (String) request.getSession().getAttribute("typeid");
addNewsForm.setTypeid(typeid);
BeanFactory factory = GetXml.getXml();
INewsService news = (INewsService)factory.getBean("userinfoServiceNews");
NewsValsession t = new NewsValsession();
String url = t.valid(request,addNewsForm);
//System.out.println(url);
if(!url.equals("faile")){
news.insertNews(addNewsForm);
}
return mapping.findForward(url);
}
public ActionForward getTypeid(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
String typeid = addNewsForm.getTypeid();
request.getSession().setAttribute("typeid",typeid);
return mapping.findForward("newok");
}
public ActionForward change(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
String typeid = (String) request.getSession().getAttribute("typeid");
addNewsForm.setTypeid(typeid);
BeanFactory factory = GetXml.getXml();
INewsService news = (INewsService)factory.getBean("userinfoServiceNews");
NewsValsession t = new NewsValsession();
String url = t.valid(request,addNewsForm);
if(!url.equals("faile")){
news.changeNews(addNewsForm);
url = "changenews";
}
return mapping.findForward(url);
}
public ActionForward changeFin(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
String typeid = (String) request.getSession().getAttribute("typeid");
addNewsForm.setTypeid(typeid);
BeanFactory factory = GetXml.getXml();
INewsService news = (INewsService)factory.getBean("userinfoServiceNews");
NewsValsession t = new NewsValsession();
String url = t.valid(request,addNewsForm);
//System.out.println(url);
if(!url.equals("faile")){
news.change2News(addNewsForm);
}
return mapping.findForward(url);
}
public ActionForward del(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
String typeid = (String) request.getSession().getAttribute("typeid");
addNewsForm.setTypeid(typeid);
BeanFactory factory = GetXml.getXml();
INewsService news = (INewsService)factory.getBean("userinfoServiceNews");
NewsValsession t = new NewsValsession();
String url = t.valid(request,addNewsForm);
//System.out.println(url);
if(!url.equals("faile")){
news.deleteNews(addNewsForm);
}
return mapping.findForward(url);
}
public ActionForward query(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddNewsForm addNewsForm = (AddNewsForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
INewsService news = (INewsService)factory.getBean("userinfoServiceNews");
NewsValsession t = new NewsValsession();
String url = t.valid(request,addNewsForm);
//System.out.println(url);
if(!url.equals("faile")){
String typeid = (String) request.getSession().getAttribute("typeid");
addNewsForm.setTypeid(typeid);
//有过改动
String strHql = "from News where typeid = ? order by date2 desc";
String strHql2 = "select count(News.date2)";
NewsHelp help = new NewsHelp();
help.queryHelp(request,strHql,strHql2,news,addNewsForm);
url = "success";
}
return mapping.findForward(url);
}
}
-------------------
package com.news.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import com.news.service.ItypeService;
import com.news.struts.form.AddtypeForm;
import com.news.utils.GetXml;
import com.news.valsession.TypeValsession;
public class AddtypeAction extends DispatchAction {
public ActionForward add(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddtypeForm addtypeForm = (AddtypeForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
ItypeService user = (ItypeService)factory.getBean("userinfoServicetype");
TypeValsession t = new TypeValsession();
String url = t.valid(request,addtypeForm);
if(!url.equals("faile")){
user.addType(addtypeForm);
}
return mapping.findForward(url);
}
public ActionForward change(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddtypeForm addtypeForm = (AddtypeForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
ItypeService user = (ItypeService)factory.getBean("userinfoServicetype");
TypeValsession t = new TypeValsession();
String url = t.valid(request,addtypeForm);
if(!url.equals("faile")){
user.changeType(addtypeForm);
url = "changetype";
}
return mapping.findForward(url);
}
public ActionForward changeFin(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddtypeForm addtypeForm = (AddtypeForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
ItypeService user = (ItypeService)factory.getBean("userinfoServicetype");
TypeValsession t = new TypeValsession();
String url = t.valid(request,addtypeForm);
if(!url.equals("faile")){
user.changeFinType(addtypeForm);
}
return mapping.findForward(url);
}
public ActionForward del(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddtypeForm addtypeForm = (AddtypeForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
ItypeService user = (ItypeService)factory.getBean("userinfoServicetype");
TypeValsession t = new TypeValsession();
String url = t.valid(request,addtypeForm);
if(!url.equals("faile")){
user.delType(addtypeForm);
}
return mapping.findForward(url);
}
public ActionForward query(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
AddtypeForm addtypeForm = (AddtypeForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
ItypeService user = (ItypeService)factory.getBean("userinfoServicetype");
TypeValsession t = new TypeValsession();
String url = t.valid(request,addtypeForm);
if(!url.equals("faile")){
String strHql = "from Newtype newtype order by newtype.date2 desc";
String strHql2 = "select count(newtype.date2)";
TypeHelp help = new TypeHelp();
help.queryHelp(request,strHql,strHql2,user,addtypeForm);
url = "success";
}
return mapping.findForward(url);
}
}
-----------------
package com.news.struts.action;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.news.service.IguestBookService;
import com.news.struts.form.GuestForm;
import com.news.utils.Check;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class GuestAction extends DispatchAction {
private IguestBookService userinfoServiceGuestBook;
public ActionForward add(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws IOException {
GuestForm guestForm = (GuestForm) form;
String rand = (String) request.getSession().getAttribute("rand");
if(guestForm.getName()!=null&&!guestForm.getName().equals("")
&&guestForm.getGuestcontent()!=null&&!guestForm.getGuestcontent().equals("")
&&!guestForm.getNewid().equals("")&&guestForm.getNewid()!=null
&&guestForm.getRand().equals(rand)&&guestForm.getRand()!=null
&&!guestForm.getRand().equals("")){
getUserinfoServiceGuestBook().add(guestForm);
guestForm.setName(null);
guestForm.setImage(null);
guestForm.setGuestcontent(null);
guestForm.setRand(null);
}
guestForm.setRand(null);
request.getSession().removeAttribute("rand");
//query(mapping, form,request,response);
//check(mapping, form,request,response);
return mapping.findForward("ok");
}
public ActionForward query(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
GuestForm guestForm = (GuestForm) form;
String strHql = "from Guestbook where newid = ? order by date2 desc";
String strHql2 = "select count(Guestbook.date2)";
GuestHelp help = new GuestHelp();
help.queryHelp(request,strHql,strHql2,userinfoServiceGuestBook,guestForm);
guestForm.setNewid(guestForm.getNewid());
return mapping.findForward("guest");
}
public ActionForward check(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws IOException {
GuestForm guestForm = (GuestForm) form;
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
Check check = new Check();
g.setColor(check.getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(check.getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
request.getSession().setAttribute("rand",sRand);
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
return null;
}
public IguestBookService getUserinfoServiceGuestBook() {
return userinfoServiceGuestBook;
}
public void setUserinfoServiceGuestBook(
IguestBookService userinfoServiceGuestBook) {
this.userinfoServiceGuestBook = userinfoServiceGuestBook;
}
}
package com.news.struts.action;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import com.news.service.IguestBookService;
import com.news.struts.form.GuestForm;
import com.news.utils.Check;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class GuestAction extends DispatchAction {
private IguestBookService userinfoServiceGuestBook;
public ActionForward add(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws IOException {
GuestForm guestForm = (GuestForm) form;
String rand = (String) request.getSession().getAttribute("rand");
if(guestForm.getName()!=null&&!guestForm.getName().equals("")
&&guestForm.getGuestcontent()!=null&&!guestForm.getGuestcontent().equals("")
&&!guestForm.getNewid().equals("")&&guestForm.getNewid()!=null
&&guestForm.getRand().equals(rand)&&guestForm.getRand()!=null
&&!guestForm.getRand().equals("")){
getUserinfoServiceGuestBook().add(guestForm);
guestForm.setName(null);
guestForm.setImage(null);
guestForm.setGuestcontent(null);
guestForm.setRand(null);
}
guestForm.setRand(null);
request.getSession().removeAttribute("rand");
//query(mapping, form,request,response);
//check(mapping, form,request,response);
return mapping.findForward("ok");
}
public ActionForward query(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) {
GuestForm guestForm = (GuestForm) form;
String strHql = "from Guestbook where newid = ? order by date2 desc";
String strHql2 = "select count(Guestbook.date2)";
GuestHelp help = new GuestHelp();
help.queryHelp(request,strHql,strHql2,userinfoServiceGuestBook,guestForm);
guestForm.setNewid(guestForm.getNewid());
return mapping.findForward("guest");
}
public ActionForward check(ActionMapping mapping,ActionForm form,
HttpServletRequest request,HttpServletResponse response) throws IOException {
GuestForm guestForm = (GuestForm) form;
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
Check check = new Check();
g.setColor(check.getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(check.getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl = random.nextInt(12);
g.drawLine(x,y,x+xl,y+yl);
}
String sRand="";
for (int i=0;i<4;i++){
String rand=String.valueOf(random.nextInt(10));
sRand+=rand;
g.setColor(new Color(20+random.nextInt(110),20+random.nextInt(110),20+random.nextInt(110)));
g.drawString(rand,13*i+6,16);
}
request.getSession().setAttribute("rand",sRand);
ServletOutputStream out = response.getOutputStream();
JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(out);
encoder.encode(image);
out.close();
return null;
}
public IguestBookService getUserinfoServiceGuestBook() {
return userinfoServiceGuestBook;
}
public void setUserinfoServiceGuestBook(
IguestBookService userinfoServiceGuestBook) {
this.userinfoServiceGuestBook = userinfoServiceGuestBook;
}
}
----------------
package com.news.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.news.page.Page;
import com.news.page.PageHelper;
import com.news.service.IguestBookService;
import com.news.struts.form.GuestForm;
public class GuestHelp {
public void queryHelp(HttpServletRequest request,String strHql,String strHql2,IguestBookService userinfoServiceGuestBook,GuestForm guestForm){
/**
* 获取参数信息
*/
int perPage = 6;
String contextPath = request.getContextPath();
int cPage = 1;
String strPage = request.getParameter("page");
if(strPage!=null && !strPage.equals("")){
cPage = Integer.parseInt(strPage);
}
PageHelper pageHelper = new PageHelper(request);
perPage = pageHelper.doCustomPerPage(perPage);
Page page = new Page();
/**
* 设置分页参数
*/
page.setPerPage(perPage);
page.setPage(cPage);
page.setHql(strHql);
page.setTotal(userinfoServiceGuestBook.getTotal(strHql2+strHql,guestForm));
page.setParam("newid="+guestForm.getNewid()+"&fun=query");
page.setContextPath(contextPath);
page.setUrl(request.getServletPath());
page.setStartRs((cPage - 1) * perPage);
/**
* 获取单页数据集
*/
List guestList = userinfoServiceGuestBook.getList(page,guestForm);
guestForm.setGuestList(guestList);
String strPageBreak = pageHelper.getPageBreakStr(page);
guestForm.setStrPageBreak(strPageBreak);
}
}
-------------------
package com.news.struts.action;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import com.news.service.IintovVewService;
import com.news.struts.form.IntoViewForm;
import com.news.utils.GetXml;
public class IntoViewAction extends DispatchAction {
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
IntoViewForm intoViewForm = (IntoViewForm) form;
BeanFactory factory = GetXml.getXml();
IintovVewService intoView = (IintovVewService) factory.getBean("userinfoServiceIntoView");
IntoViewHelp help = new IntoViewHelp();
String strHql = "from News where typeid = ? order by date2 desc";
String strHql2 = "select count(news.date2)";
help.queryHelp(request,strHql,strHql2,intoView,intoViewForm);
return mapping.findForward("into");
}
}
---------------------------
package com.news.struts.action;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import com.news.page.Page;
import com.news.page.PageHelper;
import com.news.service.IintovVewService;
import com.news.struts.form.IntoViewForm;
public class IntoViewHelp {
public void queryHelp(HttpServletRequest request,String strHql,String strHql2,IintovVewService intoView,IntoViewForm intoViewForm){
/**
* 获取参数信息
*/
int perPage = 10;
String contextPath = request.getContextPath();
int cPage = 1;
String strPage = request.getParameter("page");
if(strPage!=null && !strPage.equals("")){
cPage = Integer.parseInt(strPage);
}
PageHelper pageHelper = new PageHelper(request);
perPage = pageHelper.doCustomPerPage(perPage);
Page page = new Page();
/**
* 设置分页参数
*/
page.setPerPage(perPage);
page.setPage(cPage);
page.setHql(strHql);
page.setTotal(intoView.getTotal(strHql2+strHql,intoViewForm));
page.setParam("typeid="+intoViewForm.getTypeid()+"&fun=query");
page.setContextPath(contextPath);
page.setUrl(request.getServletPath());
page.setStartRs((cPage - 1) * perPage);
/**
* 获取单页数据集
*/
List newsList = intoView.getList(page,intoViewForm);
intoViewForm.setIntolist(newsList);
String strPageBreak = pageHelper.getPageBreakStr(page);
intoViewForm.setStrPageBreak(strPageBreak);
}
}
-----------------------package com.news.struts.action;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Random;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.actions.DispatchAction;
import org.springframework.beans.factory.BeanFactory;
import com.news.service.IloginService;
import com.news.struts.form.LoginForm;
import com.news.utils.Check;
import com.news.utils.GetXml;
import com.sun.image.codec.jpeg.JPEGCodec;
import com.sun.image.codec.jpeg.JPEGImageEncoder;
public class LoginAction extends DispatchAction {
public ActionForward login(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
LoginForm loginForm = (LoginForm) form;
response.setContentType("text/html;charset=GBK");
BeanFactory factory = GetXml.getXml();
IloginService login = (IloginService)factory.getBean("userinfoServiceLogin");
String str = login.validateUser(loginForm,request.getSession());
loginForm.setPassword(null);
return mapping.findForward(str);
}
public ActionForward check(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws IOException {
LoginForm loginForm = (LoginForm) form;
response.setHeader("Pragma","No-cache");
response.setHeader("Cache-Control","no-cache");
response.setDateHeader("Expires", 0);
response.setContentType("image/jpeg");
int width=60, height=20;
BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
Graphics g = image.getGraphics();
Random random = new Random();
Check check = new Check();
g.setColor(check.getRandColor(200,250));
g.fillRect(0, 0, width, height);
g.setFont(new Font("Times New Roman",Font.PLAIN,18));
g.setColor(check.getRandColor(160,200));
for (int i=0;i<155;i++)
{
int x = random.nextInt(width);
int y = random.nextInt(height);
int xl = random.nextInt(12);
int yl =