打印本文 打印本文 关闭窗口 关闭窗口
利用Struts结合Jbuilder7、MySql建立Web站点(2)--分页显示
作者:武汉SEO闵涛  文章来源:敏韬网  点击数2965  更新时间:2009/4/22 20:48:46  文章录入:mintao  责任编辑:mintao
ballList放入session

//do what you wish with myConnection
} catch (SQLException sqle) {
getServlet().log("Connection.process", sqle);
} finally {
//enclose this in a finally block to make
//sure the connection is closed
if(connection!=null)
try {
connection.close();
} catch (SQLException e) {
getServlet().log("Connection.close", e);
}
}

return (mapping.findForward("success"));
}
}

action.xml和struts-config.xml文件的配置

这里将不再阐述,请参考第一篇《利用Struts结合Jbuilder7、MySql建立Web站点(1)--连接数据库》

struts-config.xml:

<?xml version="1.0" encoding="ISO-8859-1" ?>

<!DOCTYPE struts-config PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 1.0//EN"
"http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">

<!--
This is the Struts configuration file for the example application,
using the proposed new syntax.

NOTE: You would only flesh out the details in the "form-bean"
declarations if you had a generator tool that used them to create
the corresponding Java classes for you. Otherwise, you would
need only the "form-bean" element itself, with the corresponding
"name" and "type" attributes.
-->


<struts-config>


<!-- ========== Data Source Configuration =============================== -->
<data-sources>
<data-source>
<set-property property="autoCommit"
value="false"/>
<set-property property="description"
value="Data Source Configuration"/>
<set-property property="driverClass"
value="org.gjt.mm.mysql.Driver"/>
<set-property property="maxCount"
value="200"/>
<set-property property="minCount"
value="20"/>
<set-property property="password"
value="sailing"/>
<set-property property="url"
value="jdbc:mysql://localhost/gdmovie"/>
<set-property property="user"
value="DateBase"/>
</data-source>
</data-sources>

<!-- ========== Form Bean Definitions =================================== -->
<form-beans>

<!-- Football form bean -->
<form-bean name="footballForm"
type="vod.model.footballForm"/>

<!-- Fun form bean -->
<form-bean name="funForm"
type="vod.model.funForm"/>

<!-- Movie form bean -->
<form-bean name="movieForm"
type="vod.model.movieForm"/>

<!-- MTV form bean -->
<form-bean name="mtvForm"
type="vod.model.mtvForm"/>

</form-beans>


<!-- ========== Global Forward Definitions ============================== -->
<global-forwards>
<forward name="welcome" path="/welcome.do"/>
</global-forwards>


<!-- ========== Action Mapping Definitions ============================== -->
<action-mappings>

<!-- Enter into welcome Page -->
<action path="/welcome"
type="vod.controller.DisplayWelcomeAction">
<forward name="success" path="/welcome.jsp"/>
</action>

<!-- Enter into morefootball Page -->
<action path="/morefootball"
type="vod.controller.MoreFootballAction">
<forward name="success" path="/morefootball.jsp"/>
</action>

<!-- Enter into viewfootball Page -->
<action path="/viewfootball"
type="vod.controller.ViewFootballAction">
<forward name="success" path="/viewfootball.jsp"/>
</action>

</action-mappings>

</struts-config>


action.xml:

<action-mappings>

<!-- Global Forward Declarations -->
<forward name="welcome" path="/welcome.do"/>

<!-- Process a user logon -->
<action path="/welcome"
actionClass="vod.controller.DisplayWelcomeAction">
<forward name="success" path="/welcome.jsp"/>
</action>
<action path="/morefootball"
actionClass="vod.controller.MoreFootballAction">
<forward name="success" path="/morefootball.jsp"/>
</action>
<action path="/viewfootball"
actionClass="vod.controller.ViewFootballAction">
<forward name="success" path="/viewfootball.jsp"/>
</action>

</action-mappings>

Jsp页面

welcome.jsp:将在这个页中加入更多足球这个链接,并且调用MoreFootballAction并且指定取第一页。

代码如下:

<%@ page contentType="text/html; charset=GB2312" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<html>
<head>
<title>
welcome
</title>
</head>
<body>
<table width="694" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="70"><div align="center">id</div></td>
<td width="110"><div align="center">footname</div></td>
<td width="82"><div align="center">viewURL</div></td>
<td width="92"><div align="center">downURL</div></td>
<td width="48"><div align="center">clicks</div></td>
<td width="41"><div align="center">sort</div></td>
<td width="40"><div align="center">intro</div></td>
<td width="66"><div align="center">commend</div></td>
<td width="61"><div align="center">date</div></td>
<td width="33"><div align="center">bad</div></td>
<td width="51"><div align="center">length</div></td>
</tr>
<logic:iterate id="football" name="footballTop">
<tr>
<td><div align="center"><bean:write name="football" property="id"/></div></td>
<td><div align="center"><bean:write name="football" property="footballName"/></div></td>
<td><div align="center"><bean:write name="football" property="viewURL"/></div></td>
<td><div align="center"><bean:write name="football" property="downURL"/></div></td>
<td><div align="center"><bean:write name="football" property="clicks"/></div></td>
<td><div align="center"><bean:write name="football" property="sort"/></div></td>
<td><div align="center"><bean:write name="football" property="intro"/></div></td>
<td><div align="center"><bean:write name="football" property="commend"/></div></td>
<td><div align="center"><bean:write name="football" property="date"/></div></td>
<td><div align="center"><bean:write name="football" property="bad"/></div></td>
<td><div align="center"><bean:write name="football" property="length"/></div></td>
</tr>
</logic:iterate>
</table>
<html:link page="/morefootball.do?page=1">更多足球</html:link>
<br>
<table width="694" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="70"><div align="center">id</div></td>
<td width="110"><div align="center">funname</div></td>
<td width="82"><div align="center">viewURL</div></td>
<td width="92"><div align="center">downURL</div></td>
<td width="48"><div align="center">clicks</div></td>
<td width="41"><div align="center">sort</div></td>
<td width="40"><div align="center">intro</div></td>
<td width="66"><div align="center">commend</div></td>
<td width="61"><div align="center">date</div></td>
<td width="33"><div align="center">bad</div></td>
<td width="51"><div align="center">length</div></td>
</tr>
<logic:iterate id="fun" name="funTop">
<tr>
<td><div align="center"><bean:write name="fun" property="id"/></div></td>
<td><div align="center"><bean:write name="fun" property="funName"/></div></td>
<td><div align="center"><bean:write name="fun" property="viewURL"/></div></td>
<td><div align="center"><bean:write name="fun" property="downURL"/></div></td>
<td><div align="center"><bean:write name="fun" property="clicks"/></div></td>
<td><div align="center"><bean:write name="fun" property="sort"/></div></td>
<td><div align="center"><bean:write name="fun" property="intro"/></div></td>
<td><div align="center"><bean:write name="fun" property="commend"/></div></td>
<td><div align="center"><bean:write name="fun" property="date"/></div></td>
<td><div align="center"><bean:write name="fun" property="bad"/></div></td>
<td><div align="center"><bean:write name="fun" property="length"/></div></td>
</tr>
</logic:iterate>
</table>
<br>
<table width="694" border="1" cellspacing="0" cellpadding="0">
<tr>
<td width="70"><div align="center">id</div></td>
<td width="110"><div align="center">moviename</div></td>
<td width="82"><div align="center"

上一页  [1] [2] [3]  下一页

打印本文 打印本文 关闭窗口 关闭窗口