1、建数据库和相应的表。
2、数据逻辑层的相关代码。
1)、通用的DAO类:CommonDAO.java
这是一个很多DAO都要继承到的通用DAO类,是我根据实践总结出来的,为了减少篇幅,这里只显示和本例相关的代码。
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.business ;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import java.lang.IllegalAccessException;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
public class DAO
{
protected DataSource ds;
/**
* 说明:取得当前查询的总记录数
*/
public int getRows ()
{
return this.count;
}
public void rsHandler (ResultSet rs, int offset, int limit)
{
try
{
count = 0;
rs.absolute ( -1) ;
count = rs.getRow () ;
if (offset <= 0)
{
rs.beforeFirst () ;
}
else
{
rs.absolute (offset) ;
}
}
catch (Exception e)
{
e.printStackTrace () ;
}
}
public DAO(DataSource ds) {
this.ds = ds;
}
public void setDataSource(DataSource ds) {
this.ds = ds;
}
protected void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
rs = null;
}
}
protected void close(PreparedStatement pstmt) {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
pstmt = null;
}
}
protected void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
protected void rollback(Connection conn) {
if (conn != null) {
try {
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
}
这个类主要是通过子类传进来的先进结果集,取得查询的记录总数,并对数据库连接进行简单的管理。
2)、对数据库进行访问:CertificateDAO.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.business;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.xindeco.common.dbconn.DbConn;
public class CertificateDAO extends DAO
{
public NationDAO(DataSource ds) {
super(ds);
}
public List findCertificateList(int offset,int limit) throws SQLException
{
int countRows = 0 ;
ArrayList list = null ;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
conn = ds.getConnection();
String sql =
"SELECT certificateID, certificateCode,certificateName,photoURL,"
+ "description,graduateID FROM TCertificate " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
/*对游标进行处理,rsHandler 方法在父类DAO中*/
this.rsHandler(rs,offset,limit);
if (rs != null && rs.next ())
{
list = new ArrayList () ;
do
{
countRows++ ;
list.add (rs2VO (rs)) ;
}
while ( (countRows++ < limit) && rs.next ()) ;
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
return list ;
}
private CertificateVO rs2VO (ResultSet rs)
{
try
{
CertificateVO certificateVO = new CertificateVO () ;
certificateVO.setCertificateID (rs.getInt ("certificateID")) ;
certificateVO.setCertificateCode (rs.getString ("certificateCode")) ;
certificateVO.setCertificateName (rs.getString ("certificateName")) ;
certificateVO.setPhotoURL (rs.getString ("photoURL")) ;
certificateVO.setDescription (rs.getString ("description")) ;
certificateVO.setGraduateID (rs.getInt ("graduateID")) ;
return certificateVO ;
}
catch (Exception ex)
{
ex.printStackTrace () ;
return null ;
}
}
}
findCertificateList(int offset,int limit)是查得所有要显示的数据,并放入ArrayList中。看过网上有些例子,把数据记录放入ArrayList的动作过程直接在while循环体里完成,如果字段多的话,会造成方法过于宠大,又不美观。 这里,数据记录放入ArrayList的动作过程由rs2VO方法完成,就比较整洁了。另外,if (rs != null && rs.next ()) 配合while ( (countRows++ < limit) && rs.next ()) 是为了程序的健壮性考虑的,稍分析一下不难得出结论。
3、建立控制器组件:CertificateAction.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.presentation;
import javax.sql.* ;
import java.util.* ;
import javax.servlet.http.* ;
import javax.servlet.* ;
import org.apache.struts.action.* ;
import org.apache.struts.util.* ;
import com.xindeco.common.Pager;
import com.xindeco.business.graduatedata.CertificateDAO ;
public class CertificateAction
extends Action
{
private static final int PAGE_LENGTH = 5 ; //每页显示5条记录
public ActionForward execute (ActionMapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response)
{
ActionForward myforward = null ;
String myaction = mapping.getParameter () ;
if (isCancelled (request))
{
return mapping.findForward ("failure") ;
}
if ("".equalsIgnoreCase (myaction))
{
myforward = mapping.findForward ("failure") ;
}
else if ("LIST".equalsIgnoreCase (myaction))
{
myforward = performList (mapping, form, request, response) ;
}
else
{
myforward = mapping.findForward ("failure") ;
}
return myforward ;
}
private ActionForward performList (ActionMapping mapping,
Actionform actionform,
HttpServletRequest request,
HttpServletResponse response)
{
try
{
DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
CertificateDAO certificateDAO = new CertificateDAO (ds) ;
int offset = 0; //翻页时的起始记录所在游标
int length = PAGE_LENGTH;
String pageOffset = request.getParameter("pager.offset");
if (pageOffset == null || pageOffset.equals("")) {
offset = 0;
} else {
offset = Integer.parseInt(pageOffset);
}
List certificateList = certificateDAO .findCertificateList (offset,length) ;
int size = certificateDAO.getRows(); // 取得总记录数
String url = request.getContextPath()+"/"+mapping.getPath()+".do";
String pagerHeader = Pager.generate(offset, size, length, url); //分页处理
request.setAttribute ("pager", pagerHeader) ;
request.setAttribute ("list", certificateList) ;
}
catch (Exception e)
{
e.printStackTrace();
return mapping.findForward ("error") ;
}
return mapping.findForward ("success") ;
}
}
CertificateAction.java主要是把数据从DAO中取出,并放入一个ArrayList 中,然后通过配置文件再软件View的JSP页。
5、建立视图listcertificate.jsp文件。
jsp代码:
代码:
--------------------------------------------------------------------------------
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<table bgcolor="#666666" cellpadding="1" cellspacing="0" border="0" width="500">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="500">
<tr>
<td bgcolor="#fecc51">&</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="500">
<tr>
<td bgcolor="#d6e0ed">
&&<bean:message key="label.list4certificate"/>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="5%"></td><td width="19%"></td><td width="76%"></td>
</tr>
<tr>
<td>
<table bgcolor="#f2f2f2" width="500" cellspacing="0" border="0">
<tr bgcolor="#bacce1">
<td><b><bean:message key="Certificate.select"/> </b></td>
<td><b><bean:message key="Certificate.certificateID"/> </b></td>
<td><b><bean:message key="Certificate.certificateCode"/></b></td>
<td><b><bean:message key="Certificate.certificateName"/></b></td>
<td><b><bean:message key="Certificate.view"/></b></td>
</tr>
<bean:write name="pager" property="description"/>
<logic:equal name="pager" property="hasPrevious" value="true">
<a href="/graduatedata/list.do?viewPage=<bean:write name="pager" property="previousPage"/>" class="a02">
Previous
</a>
</logic:equal>
<logic:equal name="pager" property="hasNext" value="true">
<a href="/graduatedata/list.do?viewPage=<bean:write name="pager" property="nextPage"/>" class="a02">
Next
</a>
</logic:equal>
<logic:notEmpty name="list" scope="request">
<logic:iterate id="certificate" name="list" type="com.xindeco.business.graduatedata.CertificateVO"scope="request">
<tr bgcolor="#FFFFFF">
<td><html:text property="name" value="<bean:write name="certificate" property="certificateID" scope="page"/>"/>
</td>
<td> <bean:write name="certificate" property="certificateID" scope="page"/></td>
<td> <bean:write name="certificate" property="certificateCode" scope="page"/></td>
<td> <bean:write name="certificate" property="certificateName" scope="page"/></td>
<td> <bean:write name="certificate" property="photoURL" scope="page"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
6、对应的配置文件struts-config.xml。
java代码:
代码:
--------------------------------------------------------------------------------
<?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>
<form-beans>
<form-bean name="certificateform" type="com.xindeco.presentation.graduatedata.Certificateform" />
</form-beans>
<global-forwards>
<forward name="error" path="/error/error.jsp" />
</global-forwards>
<action-mappings>
<action name="certificateform" parameter="LIST" path="/graduatedata/list" scope="request" type="com.xindeco.presentation.graduatedata.CertificateAction" validate="true">
<forward name="success" path="/graduatedata/listcertificate.jsp" />
</action>
</action-mappings>
……
</struts-config>
7、最后当然是最重要的分页代码了:Pager.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.common;
import java.util.* ;
public class Pager {
private static int MAX_PAGE_INDEX = 10; //页脚显示多少页
private static String HEADER = "Result page";
public static String generate(int offset, int length, int size, String url) {
if (length > size) {
String pref;
if (url.indexOf("?") > -1) {
pref = "&";
} else {
pref = "?";
}
String header = "<font face='Helvetica' size='-1'>"+HEADER+": ";
if (offset > 0) {
header += "&<a href=\""+url+pref+"pager.offset="+(offset-size)+"\">[<< Prev]</a>\n";
}
int start;
int radius = MAX_PAGE_INDEX/2*size;
if (offset < radius) {
start = 0;
} else if(offset < length-radius) {
start = offset - radius;
} else {
start = (length/size-MAX_PAGE_INDEX)*size;
}
for(int i=start;i<length && i < start + MAX_PAGE_INDEX*size;i+=size) {
if (i == offset) {
header += "<b>"+(i/size+1)+"</b>\n";
} else {
header += "&<a href=\""+url+pref+"pager.offset="+i+"\">"+(i/size+1)+"</a>\n";
}
}
if(offset < length - size) {
header += "&<a href=\""+url+pref+"pager.offset="+((int)offset+(int)size)+"\">[Next >>]</a>\n";
}
header += "</font>";
return header;
} else {
return "";
}
}
}
2、数据逻辑层的相关代码。
1)、通用的DAO类:CommonDAO.java
这是一个很多DAO都要继承到的通用DAO类,是我根据实践总结出来的,为了减少篇幅,这里只显示和本例相关的代码。
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.business ;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import java.lang.IllegalAccessException;
import java.lang.reflect.InvocationTargetException;
import org.apache.commons.beanutils.BeanUtils;
public class DAO
{
protected DataSource ds;
/**
* 说明:取得当前查询的总记录数
*/
public int getRows ()
{
return this.count;
}
public void rsHandler (ResultSet rs, int offset, int limit)
{
try
{
count = 0;
rs.absolute ( -1) ;
count = rs.getRow () ;
if (offset <= 0)
{
rs.beforeFirst () ;
}
else
{
rs.absolute (offset) ;
}
}
catch (Exception e)
{
e.printStackTrace () ;
}
}
public DAO(DataSource ds) {
this.ds = ds;
}
public void setDataSource(DataSource ds) {
this.ds = ds;
}
protected void close(ResultSet rs) {
if (rs != null) {
try {
rs.close();
} catch (SQLException e) {
}
rs = null;
}
}
protected void close(PreparedStatement pstmt) {
if (pstmt != null) {
try {
pstmt.close();
} catch (SQLException e) {
}
pstmt = null;
}
}
protected void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
protected void rollback(Connection conn) {
if (conn != null) {
try {
conn.rollback();
} catch (SQLException e) {
e.printStackTrace();
}
conn = null;
}
}
}
这个类主要是通过子类传进来的先进结果集,取得查询的记录总数,并对数据库连接进行简单的管理。
2)、对数据库进行访问:CertificateDAO.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.business;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.xindeco.common.dbconn.DbConn;
public class CertificateDAO extends DAO
{
public NationDAO(DataSource ds) {
super(ds);
}
public List findCertificateList(int offset,int limit) throws SQLException
{
int countRows = 0 ;
ArrayList list = null ;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try
{
conn = ds.getConnection();
String sql =
"SELECT certificateID, certificateCode,certificateName,photoURL,"
+ "description,graduateID FROM TCertificate " ;
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
/*对游标进行处理,rsHandler 方法在父类DAO中*/
this.rsHandler(rs,offset,limit);
if (rs != null && rs.next ())
{
list = new ArrayList () ;
do
{
countRows++ ;
list.add (rs2VO (rs)) ;
}
while ( (countRows++ < limit) && rs.next ()) ;
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
return list ;
}
private CertificateVO rs2VO (ResultSet rs)
{
try
{
CertificateVO certificateVO = new CertificateVO () ;
certificateVO.setCertificateID (rs.getInt ("certificateID")) ;
certificateVO.setCertificateCode (rs.getString ("certificateCode")) ;
certificateVO.setCertificateName (rs.getString ("certificateName")) ;
certificateVO.setPhotoURL (rs.getString ("photoURL")) ;
certificateVO.setDescription (rs.getString ("description")) ;
certificateVO.setGraduateID (rs.getInt ("graduateID")) ;
return certificateVO ;
}
catch (Exception ex)
{
ex.printStackTrace () ;
return null ;
}
}
}
findCertificateList(int offset,int limit)是查得所有要显示的数据,并放入ArrayList中。看过网上有些例子,把数据记录放入ArrayList的动作过程直接在while循环体里完成,如果字段多的话,会造成方法过于宠大,又不美观。 这里,数据记录放入ArrayList的动作过程由rs2VO方法完成,就比较整洁了。另外,if (rs != null && rs.next ()) 配合while ( (countRows++ < limit) && rs.next ()) 是为了程序的健壮性考虑的,稍分析一下不难得出结论。
3、建立控制器组件:CertificateAction.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.presentation;
import javax.sql.* ;
import java.util.* ;
import javax.servlet.http.* ;
import javax.servlet.* ;
import org.apache.struts.action.* ;
import org.apache.struts.util.* ;
import com.xindeco.common.Pager;
import com.xindeco.business.graduatedata.CertificateDAO ;
public class CertificateAction
extends Action
{
private static final int PAGE_LENGTH = 5 ; //每页显示5条记录
public ActionForward execute (ActionMapping mapping, Actionform form,
HttpServletRequest request,
HttpServletResponse response)
{
ActionForward myforward = null ;
String myaction = mapping.getParameter () ;
if (isCancelled (request))
{
return mapping.findForward ("failure") ;
}
if ("".equalsIgnoreCase (myaction))
{
myforward = mapping.findForward ("failure") ;
}
else if ("LIST".equalsIgnoreCase (myaction))
{
myforward = performList (mapping, form, request, response) ;
}
else
{
myforward = mapping.findForward ("failure") ;
}
return myforward ;
}
private ActionForward performList (ActionMapping mapping,
Actionform actionform,
HttpServletRequest request,
HttpServletResponse response)
{
try
{
DataSource ds = (DataSource) servlet.getServletContext().getAttribute(Action.DATA_SOURCE_KEY);
CertificateDAO certificateDAO = new CertificateDAO (ds) ;
int offset = 0; //翻页时的起始记录所在游标
int length = PAGE_LENGTH;
String pageOffset = request.getParameter("pager.offset");
if (pageOffset == null || pageOffset.equals("")) {
offset = 0;
} else {
offset = Integer.parseInt(pageOffset);
}
List certificateList = certificateDAO .findCertificateList (offset,length) ;
int size = certificateDAO.getRows(); // 取得总记录数
String url = request.getContextPath()+"/"+mapping.getPath()+".do";
String pagerHeader = Pager.generate(offset, size, length, url); //分页处理
request.setAttribute ("pager", pagerHeader) ;
request.setAttribute ("list", certificateList) ;
}
catch (Exception e)
{
e.printStackTrace();
return mapping.findForward ("error") ;
}
return mapping.findForward ("success") ;
}
}
CertificateAction.java主要是把数据从DAO中取出,并放入一个ArrayList 中,然后通过配置文件再软件View的JSP页。
5、建立视图listcertificate.jsp文件。
jsp代码:
代码:
--------------------------------------------------------------------------------
<%@ page contentType="text/html; charset=GBK" %>
<%@ taglib uri="/WEB-INF/struts-template.tld" prefix="template" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<table bgcolor="#666666" cellpadding="1" cellspacing="0" border="0" width="500">
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="500">
<tr>
<td bgcolor="#fecc51">&</td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0" border="0" width="500">
<tr>
<td bgcolor="#d6e0ed">
&&<bean:message key="label.list4certificate"/>
</td>
</tr>
<tr bgcolor="#FFFFFF">
<td width="5%"></td><td width="19%"></td><td width="76%"></td>
</tr>
<tr>
<td>
<table bgcolor="#f2f2f2" width="500" cellspacing="0" border="0">
<tr bgcolor="#bacce1">
<td><b><bean:message key="Certificate.select"/> </b></td>
<td><b><bean:message key="Certificate.certificateID"/> </b></td>
<td><b><bean:message key="Certificate.certificateCode"/></b></td>
<td><b><bean:message key="Certificate.certificateName"/></b></td>
<td><b><bean:message key="Certificate.view"/></b></td>
</tr>
<bean:write name="pager" property="description"/>
<logic:equal name="pager" property="hasPrevious" value="true">
<a href="/graduatedata/list.do?viewPage=<bean:write name="pager" property="previousPage"/>" class="a02">
Previous
</a>
</logic:equal>
<logic:equal name="pager" property="hasNext" value="true">
<a href="/graduatedata/list.do?viewPage=<bean:write name="pager" property="nextPage"/>" class="a02">
Next
</a>
</logic:equal>
<logic:notEmpty name="list" scope="request">
<logic:iterate id="certificate" name="list" type="com.xindeco.business.graduatedata.CertificateVO"scope="request">
<tr bgcolor="#FFFFFF">
<td><html:text property="name" value="<bean:write name="certificate" property="certificateID" scope="page"/>"/>
</td>
<td> <bean:write name="certificate" property="certificateID" scope="page"/></td>
<td> <bean:write name="certificate" property="certificateCode" scope="page"/></td>
<td> <bean:write name="certificate" property="certificateName" scope="page"/></td>
<td> <bean:write name="certificate" property="photoURL" scope="page"/></td>
</tr>
</logic:iterate>
</logic:notEmpty>
</table>
</td>
</tr>
</table>
</td>
</tr>
</table>
6、对应的配置文件struts-config.xml。
java代码:
代码:
--------------------------------------------------------------------------------
<?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>
<form-beans>
<form-bean name="certificateform" type="com.xindeco.presentation.graduatedata.Certificateform" />
</form-beans>
<global-forwards>
<forward name="error" path="/error/error.jsp" />
</global-forwards>
<action-mappings>
<action name="certificateform" parameter="LIST" path="/graduatedata/list" scope="request" type="com.xindeco.presentation.graduatedata.CertificateAction" validate="true">
<forward name="success" path="/graduatedata/listcertificate.jsp" />
</action>
</action-mappings>
……
</struts-config>
7、最后当然是最重要的分页代码了:Pager.java
java代码:
代码:
--------------------------------------------------------------------------------
package com.xindeco.common;
import java.util.* ;
public class Pager {
private static int MAX_PAGE_INDEX = 10; //页脚显示多少页
private static String HEADER = "Result page";
public static String generate(int offset, int length, int size, String url) {
if (length > size) {
String pref;
if (url.indexOf("?") > -1) {
pref = "&";
} else {
pref = "?";
}
String header = "<font face='Helvetica' size='-1'>"+HEADER+": ";
if (offset > 0) {
header += "&<a href=\""+url+pref+"pager.offset="+(offset-size)+"\">[<< Prev]</a>\n";
}
int start;
int radius = MAX_PAGE_INDEX/2*size;
if (offset < radius) {
start = 0;
} else if(offset < length-radius) {
start = offset - radius;
} else {
start = (length/size-MAX_PAGE_INDEX)*size;
}
for(int i=start;i<length && i < start + MAX_PAGE_INDEX*size;i+=size) {
if (i == offset) {
header += "<b>"+(i/size+1)+"</b>\n";
} else {
header += "&<a href=\""+url+pref+"pager.offset="+i+"\">"+(i/size+1)+"</a>\n";
}
}
if(offset < length - size) {
header += "&<a href=\""+url+pref+"pager.offset="+((int)offset+(int)size)+"\">[Next >>]</a>\n";
}
header += "</font>";
return header;
} else {
return "";
}
}
}
发表评论
-
struts2的Error filterStart解决
2011-06-21 11:53 1011错误原因: jdk1.5和tomcat5.0之间关于Tran ... -
Jsp+struts分页显示源码
2008-10-14 13:07 1841主要有三个文件:show.jsp、ShowAction.jav ... -
DispatchAction使用要点
2008-10-14 12:53 10851.action写法,注意:继承自dispatchaction ... -
DispatchAction的用法
2008-10-14 12:46 2618DispatchAction 是 Struts1.1 中的一个 ... -
struts LocaleAction 的用法
2007-06-30 20:41 1873package org.apache.struts.weba ... -
Struts 1.x与Struts 2.0的标志库比较
2007-06-17 13:06 1846对Struts 1.x与Struts 2.0的 ... -
Struts-Layout标签:Input类
2007-06-17 13:02 4124Stru ... -
Struts+Hibernate数据表示中的错误
2007-01-13 17:27 1033在 struts+ hibernate 这 ... -
Struts的logiciterate标记完成复杂循环
2007-01-13 17:25 1156使用struts中的<logic:iterate&g ... -
用struts向数据库中储存图片
2007-01-13 17:23 1205这个例子是通过用Struts的FormFile来写入到My ... -
用Struts上传多个文件的方法
2007-01-13 17:20 1107package com.xindeco.common; ...
相关推荐
Struts分页算法是Web应用开发中的重要组成部分,特别是在大型数据集展示时,为了提高用户体验,需要将数据分页展示。本算法遵循Model-View-Controller(MVC)设计模式,使得代码结构清晰,易于维护。 在Struts框架...
java的struts分页算法的具体实现.txt
本篇文章将详细介绍一种基于Spring、Struts和Hibernate框架实现的高效分页算法,并通过具体的代码示例来解释其实现原理及应用。 #### 二、分页的基本概念 分页是指将大量的数据分成多个页面展示的技术手段。在Web...
1.Struts+JDBC分页算法 1.1 创建分页控制类(如果使用kevinb.jar可以省略本步) --创建接口Pageable.java --创建实现类PageableResultSet.java 使用以这个实现类来控制分页的基本信息和操作; --可以直接使用kevinb....
综上所述,经典Struts2分页方法涉及了Action、Model、DAO、结果映射、视图、拦截器、JSP/Freemarker标签库、URL参数、分页算法和最佳实践等多个方面。通过学习和实践这些知识点,Java Web开发者能够更好地理解和应用...
### SSH2分页算法的实现 #### 一、概述 在`struts2+hibernate+spring`(简称SSH2)项目开发中,分页功能是常见的需求之一。通过合理的分页处理不仅可以提高用户体验,还能有效降低服务器的压力。本文将详细介绍...
4. **分页逻辑**:实现分页算法,根据用户选择的页码调整查询范围,并返回相应的数据。 5. **配置文件**:Struts的配置文件(struts-config.xml)中会定义Action和ActionForm,以及它们与JSP页面的映射关系。 这个...
struts2_spring_tree_分页算法 支持 oracle和sql_server 数据库
5. **分页策略**:在描述中提到的"监测模块"可能是指实现了一种分页策略,策略模式允许在运行时动态选择不同的分页算法。例如,可以有基于内存的分页,一次性加载所有数据到内存再分页;也可以有基于数据库的分页,...
Struts分页组件是基于Apache Struts框架的一个实用工具,用于在Web应用程序中实现高效、灵活的页面数据展示。在大型系统中,特别是在处理大量数据时,分页功能显得尤为重要,因为它可以提高用户体验,避免一次性加载...
计算`offset`和`limit`值是分页算法的核心部分,需要考虑到总记录数和每页显示的记录数。 接下来是JSP(JavaServer Pages)的分页实现。JSP是用于生成动态网页的Java技术。在页面上展示分页链接时,我们可以使用JSP...
在服务层,我们需要实现一个分页算法,计算总页数和当前页的数据范围。基本步骤包括: 1. 计算总记录数:通过DAO查询未分页的总数据量。 2. 计算总页数:总页数等于总记录数除以每页数量,如果余数不为0,则总页数加...
《MyBBS:Struts与Hibernate的整合及分页实现详解》 MyBBS是一个基于Struts和Hibernate框架开发的论坛系统,它充分利用了这两款强大的开源技术来构建高效、可扩展的Web应用。Struts作为经典的MVC(Model-View-...
在SSI Demo中,可能使用了某种分页组件或自定义的分页算法,将大量数据分段显示,用户可以逐页浏览,而不是一次性加载所有数据。这降低了服务器压力,提升了页面加载速度。 **集成与配置**: SSI Demo演示了如何将...
在Struts框架中,分页功能通常通过Action类和相应的视图(如JSP页面)来实现。Action类会处理用户请求,并根据参数计算出当前页码,然后从数据库中查询对应页的数据。分页通常涉及到SQL查询中的LIMIT和OFFSET关键字...
分页算法是实现分页功能的核心部分。通常,算法会考虑到总记录数、每页记录数和当前页数,以计算出正确的查询范围。在SSH框架中,这可能涉及到计算SQL的OFFSET和LIMIT子句或者使用Criteria的setFirstResult和...
分页可以通过传递页码参数来实现,而搜索可能涉及关键词匹配算法,如全文检索或简单的模糊匹配。 ### 7. 响应式设计与移动优化 考虑到多设备访问,BBS项目可能采用了响应式布局,确保在不同屏幕尺寸下都能良好显示...