web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
</web-app>
struts-config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
<action-mappings>
<action path="/pageTest" type="com.gdcn.frame.TestAction">
<forward name="page111" path="/bb.jsp" />
</action>
</action-mappings>
<!-- 定义本模块的预处理器-->
<controller contentType="text/html;charset=utf-8" locale="true" processorClass="com.gdcn.frame.MainRequestProcessor" />
<!-- 定义本模块要使用的资源文件,在国际化问题是由为有用-->
<message-resources parameter="com.gdcn.frame.frame" />
</struts-config>
public.js (只用到了一部分)
function next_focus(text)
{
if(window.event.keyCode ==13)
{
window.event.keyCode=9;
}
}
function mouseovertd (o)
{
o.style.color='#ffffff';
o.style.backgroundColor='#B3B3B3';
}
function mouseouttd (o)
{
o.style.color='#000000';
o.style.backgroundColor='';
}
function goPage(flag,currPage,formId,formAction,formTarget,formMethod,pageNumId)
{
var formObj=document.all(formId)
formObj.target=formTarget;
formObj.method=formMethod;
if(flag=='go')
{
var obj=document.all(pageNumId)
if(isNaN(obj.value))
{
obj.select();
return;
}
else
{
currPage=obj.value
}
}
pageMethod="pageMethod="+flag+"¤tPage="+currPage;
formAction=formAction+"?"+pageMethod;
formObj.action=formAction;
formObj.submit();
}
function submitForm(formId)
{
editModel_fireeagle=false
var objForm =document.all(formId);
if(Validator.Validate(objForm,2))
{
top.bottom.document.all("process").innerHTML="<img name='pro' src='"+baseURL+"/images/public/process.gif' border='0'>"
objForm.submit();
}
}
function submitFormQuery(formId)
{
var objForm =document.all(formId);
objForm.is_QUERY.value="YES"
top.bottom.document.all("process").innerHTML="<img name='pro' src='"+baseURL+"/images/public/process.gif' border='0'>"
objForm.submit();
}
function buttomOnClick(url,target)
{
top.bottom.document.all("process").innerHTML="<img name='pro' src='"+baseURL+"/images/public/process.gif' border='0'>"
if(target=='parent')
{
parent.location.href=url
}else if(target=='self')
{
location.href=url
}
}
function changeEditModel()
{
editModel_fireeagle=true
}
function isClose()
{
if(editModel_fireeagle)
{
top.bottom.document.all("process").innerHTML="<img name='pro' src='"+baseURL+"/images/public/prosessEnd.gif' border='0'>"
return exitPro
}
}
//<input type=text name=test value="" onKeypress="JHshNumberText()">
function JHshNumberText()
{
if ( !(((window.event.keyCode >= 48) && (window.event.keyCode <= 57))
|| (window.event.keyCode == 13) || (window.event.keyCode == 46)
|| (window.event.keyCode == 45)))
{
window.event.keyCode = 0 ;
}
}
document.onkeydown = openHelp
function openHelp()
{
if(window.event.keyCode==113)
{
if(top.main.document.title.indexOf("HELP")>=0)
{
showModalDialog(baseURL+"/frame/help/"+top.main.document.title);
}
}
}
DispartPage.java (taglib类)
package com.gdcn.frame;
import java.io.IOException;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.BodyTagSupport;
import org.apache.taglibs.standard.lang.support.ExpressionEvaluatorManager;
public class DispartPage extends BodyTagSupport{
private String formId; //表单id
private String formAction;//处理表单的action
private String formTarget="_self";//表单出现的窗口,默认为自己窗口里
private String formMethod="post";//提交表单的方法,默认为post
private String pageNumId; //用户输入的页面数控件的id
private int cols; //这个标签要放入table中,他生成一个tr,但里面只有一个td,
//cols表示这个td要占的列
//private Object pagerObject = null; //页面对象
/*
public Object getPagerObject() {
return pagerObject;
}
public void setPagerObject(Object value) throws JspException {
this.pagerObject = ExpressionEvaluatorManager.evaluate("pagerObject",
value.toString(), Object.class, this, pageContext);
}
*/
public String getFormAction() {
return formAction;
}
public void setFormAction(String formAction) {
this.formAction = formAction;
}
public String getFormId() {
return formId;
}
public void setFormId(String formId) {
this.formId = formId;
}
public String getFormMethod() {
return formMethod;
}
public void setFormMethod(String formMethod) {
this.formMethod = formMethod;
}
public String getFormTarget() {
return formTarget;
}
public void setFormTarget(String formTarget) {
this.formTarget = formTarget;
}
public String getPageNumId() {
return pageNumId;
}
public void setPageNumId(String pageNumId) {
this.pageNumId = pageNumId;
}
public int doStartTag() {
return EVAL_BODY_INCLUDE;
}
public int doEndTag() throws JspException {
//Pager pager = (Pager)this.getPagerObject();
Pager pager = (Pager)pageContext.getRequest().getAttribute("pager");
JspWriter out = pageContext.getOut();
StringBuffer buf = new StringBuffer();
buf.append("<tr class='ListTableRow' >");
buf.append("<td colspan='"+cols+"' >");
String disabled="";
if(pager.getTotalPages()==1||pager.getCurrentPage()==1)
disabled=" disabled='true'";
buf.append("<input type='button' name='Submit' value='第一页'"+disabled+" class='Button3' onClick=goPage('first',"+pager.getCurrentPage()+",'"+formId+"','"+formAction+"','"+formTarget+"','"+formMethod+"','"+pageNumId+"')>");
disabled=" disabled='true' ";
if(pager.getTotalPages()>1&&pager.getCurrentPage()!=1)
disabled="";
buf.append("<input type='button' name='Submit' value='上一页'"+disabled+" class='Button3' onClick=goPage('previous',"+pager.getCurrentPage()+",'"+formId+"','"+formAction+"','"+formTarget+"','"+formMethod+"','"+pageNumId+"')>");
disabled=" disabled='true'";
if(pager.getCurrentPage()<pager.getTotalPages())
disabled="";
buf.append("<input type='button' name='Submit' value='下一页'" +disabled+"class='Button3' onClick=goPage('next',"+pager.getCurrentPage()+",'"+formId+"','"+formAction+"','"+formTarget+"','"+formMethod+"','"+pageNumId+"')>");
disabled=" disabled='true'";
if(pager.getCurrentPage()!=pager.getTotalPages()&&pager.getTotalPages()!=1)
disabled="";
buf.append("<input type='button' name='Submit' value='最后一页'" +disabled+ " class='Button3' onClick=goPage('last',"+pager.getCurrentPage()+",'"+formId+"','"+formAction+"','"+formTarget+"','"+formMethod+"','"+pageNumId+"')>");
buf.append("共<font color='#0000FF'>"+pager.getTotalRows()+"</font>条记录,每页<font color='#0000FF'>"+pager.getPageSize()+"</font>条,分为<font color='#0000FF'>"+pager.getTotalPages()+"</font>页,到");
disabled=" disabled='true'";
if(pager.getTotalPages()!=1)
disabled="";
buf.append("<input type='text' name='"+pageNumId+"' "+disabled+" size='4' id='"+pageNumId+"' value='"+pager.getCurrentPage()+"' class='formStyleall'>页");
disabled=" disabled='true'";
if(pager.getTotalPages()!=1)
disabled="";
buf.append("<input type='button' name='Submit' value='跳转'"+disabled+" class='Button3' onClick=goPage('go',"+pager.getCurrentPage()+",'"+formId+"','"+formAction+"','"+formTarget+"','"+formMethod+"','"+pageNumId+"')>");
buf.append("</td>");
buf.append("</tr>");
try {
out.println(buf.toString());
} catch (IOException e) {
e.printStackTrace();
}
return EVAL_PAGE;
}
public void release() {
super.release();
}
public int getCols() {
return cols;
}
public void setCols(int cols) {
this.cols = cols;
}
}
gdcn.tld
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE taglib
PUBLIC "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN"
"http://java.sun.com/j2ee/dtds/web-jsptaglibrary_1_1.dtd">
<taglib>
<tlibversion>1.0</tlibversion>
<jspversion>1.1</jspversion>
<shortname>FireEagle Application Tag Library</shortname>
<uri>http://</uri>
<info>广东精鹰软件工作室自定义标签库 author:刘正仁</info>
<tag>
<name>dispartPage</name>
<tagclass>com.gdcn.frame.DispartPage</tagclass>
<bodycontent>empty</bodycontent>
<info>分页标签</info>
<attribute>
<name>formId</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>formAction</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
<attribute>
<name>formTarget</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>formMethod</name>
<required>false</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>pageNumId</name>
<required>true</required>
<rtexprvalue>false</rtexprvalue>
</attribute>
<attribute>
<name>cols</name>
<required>true</required>
<rtexprvalue>true</rtexprvalue>
</attribute>
</tag>
</taglib>
hibernate.cfg.xml (使用sql server 自带数据)
<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<property name="connection.driver_class">com.microsoft.jdbc.sqlserver.SQLServerDriver</property>
<property name="connection.url">jdbc:microsoft:sqlserver://127.0.0.1:1433;DatabaseName=Northwind;SelectMethod=cursor</property>
<property name="show_sql">false</property>
<property name="use_outer_join">true</property>
<property name="dialect">net.sf.hibernate.dialect.SQLServerDialect</property>
<property name="show_sql">false</property>
<!-- Mapping files -->
<mapping resource="com/gdcn/frame/Order.hbm.xml" />
</session-factory>
</hibernate-configuration>
FactoryFrameSession.java
package com.gdcn.frame;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
public class FactoryFrameSession {
public static SessionFactory sessionFactory;
static
{ long temp1=System.currentTimeMillis();
try
{
Configuration config = new Configuration().configure();
sessionFactory = config.buildSessionFactory();
}
catch(Exception e){
System.out.println("bb1");
e.printStackTrace();
System.out.println("bb2");
}
long temp2=System.currentTimeMillis();
System.out.println(temp2-temp1);
}
public Session getSession() {
Session session =null;
try {
session= sessionFactory.openSession();
} catch (HibernateException e) {
}
return session;
}
public void closeSession(Session session) {
try{
if(session!=null)
{
session.close();
}
}catch(Exception e)
{
e.printStackTrace();
}
}
public void rollbackTransaction(Transaction tr) {
try{
if(tr!=null)
tr.rollback();
}catch(Exception e)
{
}
}
public void commitTransaction(Transaction tr) {
try{
if(tr!=null)
tr.commit();
}catch(Exception e)
{
}
}
}
MainRequestProcessor.java
package com.gdcn.frame;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.RequestProcessor;
public class MainRequestProcessor extends RequestProcessor{
protected boolean processPreprocess( HttpServletRequest request, HttpServletResponse response)
{
//根据实际业务要求对模范进行预处理
boolean continueProcessing = true;
System.out.println("fdfsdf");
//HttpSession session=request.getSession();
return continueProcessing;
}
}
frame.properties(这个文件没有用到)
TestList.title=\u56fd\u5bb6\u5217\u8868
country.shortName=\u56fd\u5bb6\u540d\u7b80\u79f0
country.shortFull=\u56fd\u5bb6\u540d\u5168\u79f0
errors.login.invalidpassword=\u65e0\u6548\u5bc6\u7801
errors.login.nosuchuser=\u6b64\u7528\u6237\u4e0d\u5b58\u5728
errors.RecordAlreadyExist=\u5f53\u524d\u8bb0\u5f55\u4ee5\u5b58\u5728\uff0c\u8bf7\u68c0\u67e5
errors.RecordNotFound=\u5f53\u524d\u8bb0\u5f55\u4e0d\u5b58\u5728\u6216\u4ee5\u5220\u9664\uff0c\u60a8\u53ef\u4ee5\u5728\u5f53\u524d\u9875\u9762\u8fdb\u884c\u65b0\u589e
public.sequence.number=\u5e8f\u53f7
public.operate=\u5e8f\u53f7
public.edit=\u4fee\u6539
public.add=\u65b0\u589e
public.del=\u5220\u9664
public.save=\u4fdd\u5b58
exitPro=\u5f53\u524d\u9875\u9762\u6570\u636e\u5df2\u4fee\u6539\uff0c\u5982\u679c\u9000\u51fa\uff0c\u4fee\u6539\u7684\u6570\u636e\u5c06\u4e22\u5931\uff01
pageNum=\u8bf7\u8f93\u5165\u6570\u5b57\uff01
IConstants.java
package com.gdcn.frame;
public class IConstants {
public final static String LOGIN_USER_KEY = "USER"; //当前用户的key
public final static String FRAME_KEY = "FRAME";
public final static String FRAME_MODIFY_FLAG="modifyFlag"; //
public final static String FRAME_MODIFY_FLAG_ADD="add";
public final static String FRAME_MODIFY_FLAG_EDIT="edit";
public final static String FRAME_MODIFY_FLAG_VIEW="view";
public final static String FRAME_OBJECT_VO="objectVo";
public final static String FRAME_SAVE_FLAG="save_flag";
public final static String FRAME_SAVE_OK="ok";
public final static String FRAME_IS_FROM_SCREEN="no";
public final static int PAGE_NUMBER_800=12;
public final static int PAGE_NUMBER_1024=20;
public final static int PAGE_NUMBER=12;
}
Order.java
package com.gdcn.frame;
import java.sql.Date;
public class Order {
private Long orderID;
private int customerID;//本要配为多对一关系统,本测试没有配
private int employeeID;
private Date orderDate;
private Date requiredDate;
private Date shippedDate;
private int shipVia;
private float freight;
private String shipName;
private String shipAddress;
private String shipCity;
private String shipRegion;
private String shipPostalCode;
private String shipCountry;
public int getCustomerID() {
return customerID;
}
public void setCustomerID(int customerID) {
this.customerID = customerID;
}
public int getEmployeeID() {
return employeeID;
}
public void setEmployeeID(int employeeID) {
this.employeeID = employeeID;
}
public float getFreight() {
return freight;
}
public void setFreight(float freight) {
this.freight = freight;
}
public Date getOrderDate() {
return orderDate;
}
public void setOrderDate(Date orderDate) {
this.orderDate = orderDate;
}
public Long getOrderID() {
return orderID;
}
public void setOrderID(Long orderID) {
this.orderID = orderID;
}
public Date getRequiredDate() {
return requiredDate;
}
public void setRequiredDate(Date requiredDate) {
this.requiredDate = requiredDate;
}
public String getShipAddress() {
return shipAddress;
}
public void setShipAddress(String shipAddress) {
this.shipAddress = shipAddress;
}
public String getShipCity() {
return shipCity;
}
public void setShipCity(String shipCity) {
this.shipCity = shipCity;
}
public String getShipCountry() {
return shipCountry;
}
public void setShipCountry(String shipCountry) {
this.shipCountry = shipCountry;
}
public String getShipName() {
return shipName;
}
public void setShipName(String shipName) {
this.shipName = shipName;
}
public Date getShippedDate() {
return shippedDate;
}
public void setShippedDate(Date shippedDate) {
this.shippedDate = shippedDate;
}
public String getShipPostalCode() {
return shipPostalCode;
}
public void setShipPostalCode(String shipPostalCode) {
this.shipPostalCode = shipPostalCode;
}
public String getShipRegion() {
return shipRegion;
}
public void setShipRegion(String shipRegion) {
this.shipRegion = shipRegion;
}
public int getShipVia() {
return shipVia;
}
public void setShipVia(int shipVia) {
this.shipVia = shipVia;
}
//本应实现equals,toString,和hashCode方法.
//本测试没有使用
}
Order.hbm.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.gdcn.frame.Order" table="Orders">
<id name="orderID" type="long" unsaved-value="null" column="orderID">
<generator class="identity"/>
</id>
<property name="freight" type="float">
<column name="freight" />
</property>
<property name="shipName" type="string">
<column name="shipName" />
</property>
<property name="shipAddress" type="string">
<column name="shipAddress" />
</property>
<property name="shipCity" type="string">
<column name="shipCity" />
</property>
<property name="shipRegion" type="string">
<column name="shipRegion" />
</property>
<property name="shipPostalCode" type="string">
<column name="shipPostalCode" />
</property>
<property name="shipCountry" type="string">
<column name="shipCountry" />
</property>
</class>
</hibernate-mapping>
Pager.java
package com.gdcn.frame;
public class Pager {
private int totalRows; //总条数据
private int pageSize=IConstants.PAGE_NUMBER;//默认页面条数据
private int currentPage;//当前页
private int totalPages;//总共页数
private int startRow; //从数据中取的开始条数据
public Pager(){}
public Pager(int _pageSize,int _totalRows)
{
if(_pageSize!=0)
pageSize=_pageSize;
totalRows=_totalRows;
totalPages=totalRows/pageSize;
int mod=totalRows%pageSize;
if(mod>0)
{
totalPages++;
}
currentPage=1;
startRow=0;
}
public void first()
{
currentPage=1;
startRow=0;
}
public void previous()
{
if(currentPage==1)
{
return;
}
currentPage--;
startRow=(currentPage-1)*pageSize;
}
public void next()
{
if(currentPage<totalPages)
{
currentPage++;
}
startRow=(currentPage-1)*pageSize;
}
public void last()
{
currentPage=totalPages;
startRow=(currentPage-1)*pageSize;
}
public void refresh(int _currentPage)
{
currentPage=_currentPage;
if(currentPage>totalPages)
{
last();
}
if(currentPage<=0)
{
first();
}
}
public void go(int _currentPage)
{
refresh( _currentPage);
startRow=(currentPage-1)*pageSize;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getStartRow() {
return startRow;
}
public void setStartRow(int startRow) {
this.startRow = startRow;
}
public int getTotalPages() {
return totalPages;
}
public void setTotalPages(int totalPages) {
this.totalPages = totalPages;
}
public int getTotalRows() {
return totalRows;
}
public void setTotalRows(int totalRows) {
this.totalRows = totalRows;
}
}
PagerHelper.java
package com.gdcn.frame;
import javax.servlet.http.HttpServletRequest;
public class PagerHelper {
public static Pager getPager(HttpServletRequest request,int totalRows)
{
Integer objInt=null;
//注意,这里有一个扩展,那就是页面的条数据可以由用户在页面中自己定义.
//那么可以用rquest.getParameter("pageNumber")
//要使组件能使用,pageNumber要与开发人员约定好.
if(IConstants.FRAME_IS_FROM_SCREEN.equalsIgnoreCase("yes"))
{
//在登陆action中要设定screen的条数据
//也可以是记录当前用户的屏幕分辩率,然后再从IConstants或配置文件中去取中去取
objInt=(Integer)request.getSession().getAttribute("screen");
}
else
{
objInt=new Integer(IConstants.PAGE_NUMBER);
}
int pageSize=0;
if(objInt!=null)
pageSize=objInt.intValue();
Pager pager=new Pager(pageSize,totalRows);
//当前页currentPage是由我们的taglib中定义的,他相当于页面的一个关键字,就是说在页面上
//不要定义与currentPage相同名字的控件
String currentPage=request.getParameter("currentPage");
if(currentPage==null||currentPage.equals(""))
{
currentPage="1";
}
if(currentPage!=null)
{
pager.refresh(Integer.parseInt(currentPage));
}
//当前页pageMethod是由我们的taglib中定义的,他相当于页面的一个关键字,就是说在页面上
//不要定义与pageMethod相同名字的控件
String pagerMethod=request.getParameter("pageMethod");
if(pagerMethod!=null)
{
if(pagerMethod.equalsIgnoreCase("first"))
pager.first();
else if(pagerMethod.equalsIgnoreCase("previous"))
pager.previous();
else if(pagerMethod.equalsIgnoreCase("next"))
pager.next();
else if(pagerMethod.equalsIgnoreCase("last"))
pager.last();
else if(pagerMethod.equalsIgnoreCase("go"))
pager.go(Integer.parseInt(currentPage));
}
return pager;
}
}
TestAction.java
package com.gdcn.frame;
import java.util.List;
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;
public class TestAction extends org.apache.struts.action.Action{
public static final String FORWARD_CodeTypeList = "page111";
public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception
{
TestDAO test=new TestDAO();
int rowsCodeType=test.getRows();
Pager pager=PagerHelper.getPager(request,rowsCodeType);
List pageTest=test.findObjectWithPage(pager.getPageSize(),pager.getStartRow());
System.out.println("hfghfgh====="+pageTest);
request.setAttribute("page",pageTest);
request.setAttribute("pager",pager);
return mapping.findForward(FORWARD_CodeTypeList);
}
}
TestDAO.java
package com.gdcn.frame;
import java.util.ArrayList;
import java.util.List;
import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Query;
import net.sf.hibernate.Session;
import net.sf.hibernate.Transaction;
public class TestDAO {
public int getRows() {
String sql = "from Order as o";
FactoryFrameSession factoryFrameSession=new FactoryFrameSession();
Session session=null;
Transaction tx = null;
Query query=null;
List l=null;
try {
session=factoryFrameSession.getSession();
tx = session.beginTransaction();
query = session.createQuery(sql);
tx.commit();
l = query.list();
if (l == null || l.isEmpty()) {
return 0;
}
} catch (HibernateException e) {
factoryFrameSession.rollbackTransaction(tx);
e.printStackTrace();
}
finally
{
factoryFrameSession.closeSession(session);
}
return l.size();
}
public List findObjectWithPage(int pageSize, int startRow) {
FactoryFrameSession factoryFrameSession=new FactoryFrameSession();
List returnValue = new ArrayList();
Session session = null;
Transaction tx = null;
try {
session = factoryFrameSession.getSession();
tx = session.beginTransaction();
String query="from Order o where 1=1";
Query q = session.createQuery(query);
q.setFirstResult(startRow);
q.setMaxResults(pageSize);
returnValue = q.list();
tx.commit();
} catch (HibernateException ex) {
factoryFrameSession.rollbackTransaction(tx);
} finally {
factoryFrameSession.closeSession(session);
}
return returnValue;
}
}
bb.jsp
<%@ page contentType="text/html; charset=utf-8" language="java"%>
<!--引入系统中要用的类-->
<%@page import="java.util.*"%>
<%@page import="com.gdcn.frame.Order"%>
<%@taglib uri="/WEB-INF/gdcn.tld" prefix="gdcn"%>
<html>
<head>
<link href="<%=request.getContextPath()%>/main.css" rel="stylesheet" type="text/css">
<script type="text/javascript" src="<%=request.getContextPath()%>/public.js"></script>
<title>codeType_HELP_000002.htm</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body >
<form action="<%=request.getContextPath()%>/pageTest.do" method="post" name="codeTypeList" id="codeTypeList">
<% String tableStyle="width=\"100%\" border=\"1\" cellSpacing=\"0\" cellpadding=\"3\" bordercolorlight=\"#E2D7CF\" bordercolordark=\"#FAF8F6\"";
%>
<table <%=tableStyle%>>
<tr class="ListTableHeader">
<td colspan="7" ><div align="center"><strong>分页示例</strong></div></td>
</tr>
</table>
<table <%=tableStyle%> id="codeTypeTable">
<%
List pages=(List)request.getAttribute("page");
System.out.println("pages==="+pages);
if(pages!=null&&!pages.isEmpty())
{
for(int i=0;i<pages.size();i++)
{
Order order=(Order)pages.get(i);
System.out.println(order.getShipAddress());
%>
<tr class=ListTableRow >
<td width="50%" >(<%=i+1%>)</td>
<td width="50%" ><%=order.getShipAddress()%></td>
</tr>
<%}
}
String action=request.getContextPath()+"/pageTest.do";
%>
<gdcn:dispartPage formId="codeTypeList" formAction="<%=action%>" pageNumId="pageNum" cols="2"/>
</table>
</form>
</body>
</html>
main.css
a:link{font-family: "Arial"; color:#000000;text-decoration:underline}
a:visited{font-family: "Arial"; color:#000000;text-decoration:underline}
a:hover{font-family: "Arial"; color:#000000;text-decoration:none}
a:active{font-family: "Arial";color:#000000;text-decoration:underline}
BODY{
background-color:#FAF8F6 ;
margin:0 0 0 0 ;
font-family: "Arial";
font-size:12px ;
SCROLLBAR-FACE-COLOR: #f6f6f6; SCROLLBAR-HIGHLIGHT-COLOR: #ffffff; SCROLLBAR-SHADOW-COLOR: #cccccc; SCROLLBAR-3DLIGHT-COLOR: #cccccc; SCROLLBAR-ARROW-COLOR: #330000; SCROLLBAR-TRACK-COLOR: #f6f6f6; SCROLLBAR-DARKSHADOW-COLOR: #ffffff;
}
td{
line-height:12px ;
font-family: "Arial";
font-size:12px ;
}
.Button2{
border:1px buttonhighlight outset;
background-image:url(../images/ButtonBg.gif);
height:18px ;
width:40px ;
padding-top:0px ;
color:#000099 ;
font-family: "Arial";
font-size:10px;
}
.Button3{
border:1px buttonhighlight outset;
background-image:url(../images/ButtonBg.gif);
height:22px ;
width:60px ;
padding-top:2px ;
color:#000099 ;
font-family: "Arial";
font-size:12px;
}
.Button4{
border:1px buttonhighlight outset;
background-image:url(../images/ButtonBg.gif);
height:22px ;
width:80px ;
padding-top:2px ;
color:#000099 ;
font-family: "Arial";
font-size:12px;
}
.Button5{
border:1px buttonhighlight outset;
background-image:url(../images/ButtonBg.gif);
height:22px ;
width:100px ;
padding-top:2px ;
color:#000099 ;
font-family: "Arial";
font-size:12px;
}
.Button6{
border:1px buttonhighlight outset;
background-image:url(../images/ButtonBg.gif);
height:22px ;
width:120px ;
padding-top:2px ;
color:#000099 ;
font-family: "Arial";
font-size:12px;
}
.ListTableHeader{
background-image:url(../images/ButtonBg.gif) ;
height:22px ;
font-family: "Arial";
font-size:12px ;
}
.ListTableRow{
height:12px ;
background-color:#FAF8F6 ;
color:#000000 ;
font-family: "Arial";
margin:0 0 0 0;
font-size:12px ;
}
.Row1{
height:22px ;
background-color:#e8e8e8 ;
color:#000000 ;
font-family: "Arial";
margin:0 0 0 0;
font-size:12px ;
cursor:hand ;
}
.Row2{
height:22px ;
background-color:#ffffff ;
color:#000000 ;
font-family: "Arial";
margin:0 0 0 0;
font-size:12px ;
cursor:hand ;
}
.Row{
height:10px ;
background-color:#ffffff ;
color:#000000 ;
font-family: "Arial";
margin:0 0 0 0;
font-size:12px ;
cursor:hand ;
}
.formStyleall {
BORDER-RIGHT: #7f7f7f 1px solid; BORDER-TOP: #7f7f7f 1px solid; FONT: 11px Verdana, Arial, Helvetica, sans-serif; BORDER-LEFT: #7f7f7f 1px solid; COLOR: #2f3f5f; BORDER-BOTTOM: #7f7f7f 1px solid; BACKGROUND-COLOR: #ffffff
}
.sort-arrow.descending {
background-image: url("../images/public/down.gif");
}
.sort-arrow.ascending {
background-image: url("../images/public/up.gif");
}
posted on 2008-01-24 13:58
李建軍 阅读(315)
评论(0) 编辑 收藏 所属分类:
struts