本文共 28658 字,大约阅读时间需要 95 分钟。
网上有很多关于SSH架构的实例文章,但都显得复杂,我想,入门的朋友,还是希望从最简单的CRUD操作开始,一些复杂的数据库关系,逻辑关系,以后在项目中就能碰到,所以,本文定位于从零开始的一个SSH架构的例子,功能很简单,就是完成一个人员的CRUD操作,麻雀虽小,五脏俱全,希望能对从来没有接触过三者结合开发的朋友带来一点点帮助,这个例子,也算是我的入门实例,从此,开始Struts+Spring+Hibernate之旅
开发工具:MyEclipse5.1+Tomcat+Mysql
开发前准备:数据库安装,tomcat安装,下载jar包这些就不费口水了,直接切入正题吧
CREATE TABLE `people` (
`id` int(11) NOT NULL auto_increment,
`name` varchar(100) default NULL,
`location` varchar(100) default NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=gb2312 ROW_FORMAT=COMPRESSED;
首先,建立工程和package,以下是我的工程目录
action
DeletePeopleAction.java //删除人员action
EditPeopleAction.java //编辑人员action第一步,读取需要修改的人员资料
EditPeopleActionDo.java //修改人员action
ListPeopleAction.javaSave //显示人员列表action
SavePeopleAction.java //新增人员action
SearchPeopleAction.java //查找人员action
dao
IDAO.java //数据库操作接口
StudentDAOImpl.java //数据库操作实现
domain
AbstractPeople.java //实体抽象类
People.hbm.xml //数据库映射
People.java //实体类
service
IService.java //服务层接口
StudentManagerImpl.java //服务层实现
util
Character.java //字符编码过滤器
PageSupport.java //分页
applicationContext_hibernate.xml //Spring配置文件(hibernate部分)
applicationContext_service.xml //Spring配置文件(Service部分)
JSP:这几个jsp从名字就能看出功能,不说了
addStudent.jsp
editStudent.jsp
searchList.jsp
searchStudent.jsp
studentList.jsp
代码:
applicationContext_hibernate.xml
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< beans >
<!--
<bean id="dataSource" class="org.springframework.jndi.JndiObjectFactoryBean">
<property name="jndiName">
<value>java:comp/env/jdbc/StudentManager</value>
</property>
</bean>
-->
< bean id ="dataSource" class ="org.springframework.jdbc.datasource.DriverManagerDataSource" >
< property name ="driverClassName" >
< value > com.mysql.jdbc.Driver </ value >
</ property >
< property name ="url" >
< value > jdbc:mysql://localhost:3306/studentmanager </ value >
</ property >
< property name ="username" >
< value > root </ value >
</ property >
< property name ="password" >
< value > 1234 </ value >
</ property >
</ bean >
< bean id ="TransactionManager" class ="org.springframework.jdbc.datasource.DataSourceTransactionManager" >
< property name ="dataSource" >
< ref bean ="dataSource" />
</ property >
</ bean >
< bean id ="sessionFactory"
class ="org.springframework.orm.hibernate3.LocalSessionFactoryBean" >
< property name ="dataSource" >
< ref local ="dataSource" />
</ property >
< property name ="hibernateProperties" >
< props >
< prop key ="hibernate.dialect" >
org.hibernate.dialect.MySQLDialect
</ prop >
< prop key ="hibernate.show_sql" > true </ prop >
< prop key ="hibernate.cache.use_query_cache" > true </ prop >
< prop key ="hibernate.cache.provider_class" >
org.hibernate.cache.HashtableCacheProvider
</ prop >
</ props >
</ property >
<!--
<property name="mappingDirectoryLocations">
<list>
<value>classpath:/domain</value>
</list>
</property> -->
< property name ="mappingResources" >
< list >
< value > domain/People.hbm.xml </ value >
</ list >
</ property >
</ bean >
< bean id ="StudentDAO" class ="dao.StudentDAOImpl" >
< property name ="sessionFactory" >
< ref local ="sessionFactory" />
</ property >
</ bean >
</ beans >
applicationContext_service.xml
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd" > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< beans > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< bean id ="transactionManager" class ="org.springframework.orm.hibernate3.HibernateTransactionManager" >
< property name ="sessionFactory" >
< ref bean ="sessionFactory" />
</ property >
</ bean >
< bean id ="studentManager" class ="org.springframework.transaction.interceptor.TransactionProxyFactoryBean" >
< property name ="transactionManager" >
< ref bean ="transactionManager" ></ ref >
</ property >
< property name ="target" >
< bean class ="service.StudentManagerImpl" >
< property name ="studentDAO" >
< ref bean ="StudentDAO" />
</ property >
</ bean >
</ property >
< property name ="transactionAttributes" >
< props >
< prop key ="save*" > PROPAGATION_REQUIRED </ prop >
< prop key ="list*" > PROPAGATION_REQUIRED,readOnly </ prop >
< prop key ="delete*" > PROPAGATION_REQUIRED </ prop >
< prop key ="get*" > PROPAGATION_REQUIRED,readOnly </ prop >
< prop key ="edit*" > PROPAGATION_REQUIRED </ prop >
< prop key ="search*" > PROPAGATION_REQUIRED </ prop >
</ props >
</ property >
< property name ="proxyTargetClass" >
< value > true </ value >
</ property >
</ bean >
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ beans >
Web.xml
<? xml version="1.0" encoding="UTF-8" ?>
< web-app xmlns ="http://java.sun.com/xml/ns/j2ee" xmlns:xsi ="http://www.w3.org/2001/XMLSchema-instance" version ="2.4" xsi:schemaLocation ="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >
< context-param >
< param-name > contextConfigLocation </ param-name > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< param-value >
/WEB-INF/classes/applicationContext_service.xml,
/WEB-INF/classes/applicationContext_hibernate.xml
</ param-value >
</ context-param >
< resource-ref >
< description > SqlServer Datasource example </ description >
< res-ref-name > jdbc/StudentManager </ res-ref-name >
< res-type > javax.sql.DataSource </ res-type >
< res-auth > Container </ res-auth >
</ resource-ref >
< filter >
< filter-name > hibernateFilter </ filter-name >
< filter-class >
org.springframework.orm.hibernate3.support.OpenSessionInViewFilter
</ filter-class >
< init-param >
< param-name > singleSession </ param-name >
< param-value > true </ param-value >
</ init-param >
</ filter >
< filter-mapping >
< filter-name > hibernateFilter </ filter-name >
< url-pattern > *.do </ url-pattern >
</ filter-mapping > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< listener >
< listener-class > org.springframework.web.context.ContextLoaderListener </ listener-class >
</ listener >
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< servlet >
< servlet-name > action </ servlet-name >
< servlet-class > org.apache.struts.action.ActionServlet </ servlet-class >
< init-param >
< param-name > config </ param-name >
< param-value > /WEB-INF/struts-config.xml </ param-value >
</ init-param >
< init-param >
< param-name > debug </ param-name >
< param-value > 3 </ param-value >
</ init-param >
< init-param >
< param-name > detail </ param-name >
< param-value > 3 </ param-value >
</ init-param >
< load-on-startup > 0 </ load-on-startup >
</ servlet >
< servlet-mapping >
< servlet-name > action </ servlet-name >
< url-pattern > *.do </ url-pattern >
</ servlet-mapping >
</ web-app > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
struts-config.xml
<? xml version="1.0" encoding="UTF-8" ?>
<! DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd" > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
< struts-config >
< data-sources />
< form-beans >
< form-bean name ="people" type ="domain.People" ></ form-bean >
</ form-beans >
< global-exceptions />
< global-forwards />
< action-mappings >
< action path ="/savePeople" name ="people" type ="action.SavePeopleAction" >
< forward name ="success" path ="/listPeople.do" ></ forward >
</ action >
< action path ="/listPeople" name ="people" type ="action.ListPeopleAction" >
< forward name ="success" path ="/studentList.jsp" ></ forward >
</ action >
< action path ="/deletePeople" name ="people" type ="action.DeletePeopleAction" >
< forward name ="success" path ="/studentList.jsp" ></ forward >
</ action >
< action path ="/editPeople" name ="people" type ="action.EditPeopleAction" >
< forward name ="success" path ="/editStudent.jsp" ></ forward >
</ action >
< action path ="/editPeopleDo" name ="people" type ="action.EditPeopleActionDo" >
< forward name ="success" path ="/studentList.jsp" ></ forward >
</ action >
< action path ="/searchPeople" name ="people" type ="action.SearchPeopleAction" >
< forward name ="success" path ="/searchList.jsp" ></ forward >
</ action > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ action-mappings >
< controller contentType ="text/html;charset=gb2312"
processorClass ="util.Character" />
< message-resources parameter ="" />
</ struts-config > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
DeletePeopleAction.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class DeletePeopleAction extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
Integer id=new Integer(request.getParameter("id"));
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
manager.deletePeople(id);
List studentList=manager.listPeople(0,5,"from People");
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", 1);
return mapping.findForward("success");
}
} EditPeopleAction.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class EditPeopleAction extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
String id=request.getParameter("id");
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
People people=(People)manager.getPeople(new Integer(id));
request.setAttribute("id", id);
request.setAttribute("name", people.getName());
request.setAttribute("location", people.getLocation());
return mapping.findForward("success");
}
} EditPeopleActionDo.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class EditPeopleActionDo extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
People people=(People)form;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
People sPeople=(People)manager.getPeople(new Integer(people.getId()));
sPeople.setName(people.getName());
sPeople.setLocation(people.getLocation());
manager.editPeople(sPeople);
List studentList=manager.listPeople(0,5,"from People");
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", 1);
return mapping.findForward("success");
}
} ListPeopleAction.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import util.PageSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class ListPeopleAction extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
String page=request.getParameter("page");![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int firstRow=0;
int lastRow=0;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
PageSupport sPage=new PageSupport(page);
sPage.setPagetotal(manager.listPeople().size());
firstRow=sPage.calcFirstPage();
lastRow=sPage.calcLastPage();
List studentList=manager.listPeople(firstRow-1,lastRow,"from People");
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", sPage.getThispage());
return mapping.findForward("success");
}
} SavePeopleAction.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class SavePeopleAction extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
People people=(People)form;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
manager.savePeople(people);
return mapping.findForward("success");
}
} SearchPeopleAction.java
/**/ /*
* Generated by MyEclipse Struts
* Template path: templates/java/JavaClass.vtl
*/
package action;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.springframework.web.struts.ActionSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import service.StudentManagerImpl;
import util.PageSupport;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* MyEclipse Struts
* Creation date: 01-17-2007
*
* XDoclet definition:
* @struts.action validate="true"
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class SearchPeopleAction extends ActionSupport ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
public ActionForward execute(ActionMapping mapping, ActionForm form,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletRequest request, HttpServletResponse response) ...{
People people=(People)form;
String page=request.getParameter("page");![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int firstRow=0;
int lastRow=0;
String name=people.getName();
String location=people.getLocation();
String hql="from People where name="+name+" and location="+location;
StudentManagerImpl manager=(StudentManagerImpl)getWebApplicationContext().getBean("studentManager");
PageSupport sPage=new PageSupport(page);
sPage.setPagetotal(manager.searchPeople(hql).size());
firstRow=sPage.calcFirstPage();
lastRow=sPage.calcLastPage();
List studentList=manager.searchPeople(firstRow-1, lastRow, hql);
request.setAttribute("studentList", studentList);
request.setAttribute("currentPage", sPage.getThispage());
return mapping.findForward("success");
}
} IDAO.java
package dao;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.hibernate.criterion.DetachedCriteria;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public interface IDAO ... {
public void save(Object obj);
public List list(final int firstRow,final int lastRow,final String hql);
public List list();
public void delete(Object obj);
public Object getPeople(Integer id);
public void editPeople(Object obj);
public List searchPeople(final int firstRow,final int lastRow,final String hql);
public List searchPeople(final String sql);
}
StudentDAOImpl.java
package dao;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.hibernate.Criteria;
import org.hibernate.HibernateException;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.orm.hibernate3.HibernateCallback;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class StudentDAOImpl extends HibernateDaoSupport implements IDAO ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List searchPeople(final int firstRow,final int lastRow,final String hql)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
return getHibernateTemplate().executeFind(new HibernateCallback() ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List searchPeople(final String hql)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
return getHibernateTemplate().executeFind(new HibernateCallback() ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
List list = query.list();
return list;
}
});
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void save(Object obj) ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(obj instanceof People)...{
People people=(People)obj;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
try...{
getHibernateTemplate().save(people);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}catch(Exception e)...{
e.printStackTrace();
}
}
} ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List list()...{
return getHibernateTemplate().find("from People");
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List list(final int firstRow,final int lastRow,final String hql)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
return getHibernateTemplate().executeFind(new HibernateCallback() ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Object doInHibernate(Session s) throws HibernateException, SQLException ...{
Query query = s.createQuery(hql);
query.setFirstResult(firstRow);
query.setMaxResults(lastRow);
List list = query.list();
return list;
}
});
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void editPeople(Object obj)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(obj instanceof People)...{
People people=(People)obj;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
try...{
getHibernateTemplate().saveOrUpdate(people);![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
}catch(Exception e)...{
e.printStackTrace();
}
}
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Object getPeople(Integer id)...{
return getHibernateTemplate().get(People.class, id);
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void delete(Object obj)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(obj instanceof People)...{
getHibernateTemplate().delete((People)obj);
}
}
}
AbstractPeople.java
package domain;
import org.apache.struts.action.ActionForm;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public abstract class AbstractPeople extends ActionForm implements java.io.Serializable ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Fields ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
private Integer id;
private String name;
private String location;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Constructors![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//** default constructor */![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public AbstractPeople() ...{
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//** full constructor */![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public AbstractPeople(String name, String location) ...{
this.name = name;
this.location = location;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Property accessors![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Integer getId() ...{
return this.id;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setId(Integer id) ...{
this.id = id;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public String getName() ...{
return this.name;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setName(String name) ...{
this.name = name;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public String getLocation() ...{
return this.location;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setLocation(String location) ...{
this.location = location;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
} People.hbm.xml
<? xml version="1.0" encoding="utf-8" ?>
<! DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd" >
<!--
Mapping file autogenerated by MyEclipse - Hibernate Tools
-->
< hibernate-mapping package ="domain" >
< class name ="People" table ="people" >
< id name ="id" type ="java.lang.Integer" >
< column name ="id" />
< generator class ="increment" ></ generator >
</ id >
< property name ="name" type ="java.lang.String" >
< column name ="name" length ="100" />
</ property >
< property name ="location" type ="java.lang.String" >
< column name ="location" length ="100" />
</ property >
</ class >
</ hibernate-mapping >
People.java
package domain;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
/** */ /**
* People generated by MyEclipse - Hibernate Tools
*/ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class People extends AbstractPeople implements java.io.Serializable ... { ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
// Constructors![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//** default constructor */![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public People() ...{
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
/** *//** full constructor */![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public People(String name, String location) ...{
super(name, location);
}
}
IService.java
package service;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public interface IService ... {
public void savePeople(Object obj);
public List listPeople(int firstRow,int lastRow,String hql);
public List listPeople();
public void deletePeople(Integer id);
public Object getPeople(Integer id);
public void editPeople(Object obj);
public List searchPeople(String hql);
public List searchPeople(int firstRow,int lastRow,String hql);
}
StudentManagerImpl.java
package service;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.util.ArrayList;
import java.util.List;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import dao.IDAO;
import domain.People;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class StudentManagerImpl implements IService ... {
private IDAO studentDAO;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void savePeople(Object obj) ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(obj instanceof People)...{
People people=(People)obj;
studentDAO.save(people);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List searchPeople(String hql)...{
return studentDAO.searchPeople(hql);
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List searchPeople(int firstRow,int lastRow,String hql)...{
return studentDAO.searchPeople(firstRow, lastRow, hql);
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List listPeople(int firstRow,int lastRow,String hql)...{
List peopleList=new ArrayList();
peopleList=studentDAO.list(firstRow,lastRow,hql);
return peopleList;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public List listPeople()...{
return studentDAO.list();
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void editPeople(Object obj)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(obj instanceof People)...{
People people=(People)obj;
studentDAO.editPeople(people);
}
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public Object getPeople(Integer id)...{
return studentDAO.getPeople(id);
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void deletePeople(Integer id)...{
studentDAO.delete(this.getPeople(id));
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public IDAO getStudentDAO() ...{
return studentDAO;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setStudentDAO(IDAO studentDAO) ...{
this.studentDAO = studentDAO;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
Character.java
package util;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import java.io.IOException;
import java.io.UnsupportedEncodingException;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.RequestProcessor;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class Character extends RequestProcessor ... {
protected boolean processRoles(HttpServletRequest request,
HttpServletResponse response, ActionMapping mapping)![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
throws IOException, ServletException ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return super.processRoles(request, response, mapping);
}
protected void processContent(HttpServletRequest request,![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
HttpServletResponse response) ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
try ...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
request.setCharacterEncoding("gb2312");
System.out.println(request.getCharacterEncoding());![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
} catch (UnsupportedEncodingException e) ...{
e.printStackTrace();
}
super.processContent(request, response);
}
}
PageSupport.java
package util;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
public class PageSupport ... {
int thispage = 0;// 当前页数
int pagesize = 5;// 每页最大记录数
int firstpage = 0;// 记录开始的位置
int lastpage = 0;// 记录结束的位置
int pagetotal = 0;// 总记录数
int pagenums = 0;// 总页数
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public PageSupport(String page)...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(page==null||page.equals(""))...{
thispage=1;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
else...{
thispage=Integer.parseInt(page);
}
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int calcFirstPage()...{
pagenums = pagetotal / pagesize;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if (pagetotal % pagesize != 0)...{
pagenums = pagenums + 1;
}
if (thispage > pagenums)
thispage = pagenums;![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
else if(thispage<=0)...{
thispage=1;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
if(thispage<=1)...{
firstpage=1;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
else...{
firstpage = (thispage-1) * pagesize+1;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.firstpage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int calcLastPage()...{ ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
return this.pagesize;
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getFirstpage() ...{
return firstpage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setFirstpage(int firstpage) ...{
this.firstpage = firstpage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getLastpage() ...{
return lastpage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setLastpage(int lastpage) ...{
this.lastpage = lastpage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getPagenums() ...{
return pagenums;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setPagenums(int pagenums) ...{
this.pagenums = pagenums;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getPagesize() ...{
return pagesize;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setPagesize(int pagesize) ...{
this.pagesize = pagesize;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getPagetotal() ...{
return pagetotal;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setPagetotal(int pagetotal) ...{
this.pagetotal = pagetotal;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public int getThispage() ...{
return thispage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
public void setThispage(int thispage) ...{
this.thispage = thispage;
}![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
}
addStudent.jsp
<% ... @ page language="java" contentType="text/html;charset=gb2312" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head >
</ head >
< body >
< form action ="/StudentManager/savePeople.do" method ="post" >
姓名: < input type ="text" name ="name" />< br >
籍贯: < input type ="text" name ="location" />< br >
< input type ="submit" name ="submit" value ="提交" />
</ form >
< a href ="searchStudent.jsp" > 查询 </ a >
</ body >
</ html >
editStudent.jsp
<% ... @ page language="java" contentType="text/html;charset=gb2312" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head >
</ head >
< body >
< form action ="/StudentManager/editPeopleDo.do" method ="post" >
< input type ="hidden" name ="id" value ="<%=request.getAttribute(" id") % > "/>
姓名: < input type ="text" name ="name" value ="<%=request.getAttribute(" name") % > "/> < br >
籍贯: < input type ="text" name ="location" value ="<%=request.getAttribute(" location") % > "/> < br >
< input type ="submit" name ="submit" value ="提交" />
</ form >
</ body >
</ html >
searchList.jsp
<% ... @ page language="java" contentType="text/html;charset=gb2312" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int previousPage=((Integer)request.getAttribute("currentPage")).intValue()-1;
int nextPage=((Integer)request.getAttribute("currentPage")).intValue()+1;
%>
</ head >
< body >
< table border =1 >
< tr >
< td > 姓名 </ td >< td > 籍贯 </ td >< td align ="center" > 操作 </ td >
</ tr >
< logic:present name ="studentList" scope ="request" >
< logic:iterate id ="student" name ="studentList" >
< tr >
< td >< bean:write name ="student" property ="name" /></ td >
< td >< bean:write name ="student" property ="location" /></ td >
< td align ="center" >< a href ="/StudentManager/deletePeople.do?id=<bean:write name=" student" property ="id" /> ">删除 </ a > < a href ="/StudentManager/editPeople.do?id=<bean:write name=" student" property ="id" /> ">修改 </ a ></ td >
</ tr >
</ logic:iterate >
</ logic:present >
</ table >
< a href ="/StudentManager/searchPeople.do?page=<%=previousPage%>" > 上一页 </ a >
< a href ="/StudentManager/searchPeople.do?page=<%=nextPage%>" > 下一页 </ a >
< br >< br >
< a href ="addStudent.jsp" > 新增 </ a >
< a href ="searchStudent.jsp" > 查询 </ a >
</ body >
</ html >
searchStudent.jsp
<% ... @ page language="java" contentType="text/html;charset=gb2312" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head >
</ head >
< body >
输入查询条件:
< form action ="/StudentManager/searchPeople.do" method ="post" >
姓名: < input type ="text" name ="name" />< br >
籍贯: < input type ="text" name ="location" />< br >
< input type ="submit" name ="submit" value ="查询" />
</ form > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</ body >
< a href ="addStudent.jsp" > 新增 </ a >
</ html >
studentList.jsp
<% ... @ page language="java" contentType="text/html;charset=gb2312" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %> ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... @ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" >
< html >
< head > ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
<% ... ![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int previousPage=((Integer)request.getAttribute("currentPage")).intValue()-1;
int nextPage=((Integer)request.getAttribute("currentPage")).intValue()+1;
%>
</ head >
< body >
< table border =1 >
< tr >
< td > 姓名 </ td >< td > 籍贯 </ td >< td align ="center" > 操作 </ td >
</ tr >
< logic:present name ="studentList" scope ="request" >
< logic:iterate id ="student" name ="studentList" >
< tr >
< td >< bean:write name ="student" property ="name" /></ td >
< td >< bean:write name ="student" property ="location" /></ td >
< td align ="center" >< a href ="/StudentManager/deletePeople.do?id=<bean:write name=" student" property ="id" /> ">删除 </ a > < a href ="/StudentManager/editPeople.do?id=<bean:write name=" student" property ="id" /> ">修改 </ a ></ td >
</ tr >
</ logic:iterate >
</ logic:present >
</ table >
< a href ="/StudentManager/listPeople.do?page=<%=previousPage%>" > 上一页 </ a >
< a href ="/StudentManager/listPeople.do?page=<%=nextPage%>" > 下一页 </ a >
< br >< br >
< a href ="addStudent.jsp" > 新增 </ a >
< a href ="searchStudent.jsp" > 查询 </ a >
</ body >
</ html > 转载地址:http://yzihb.baihongyu.com/