1.action
package com.bc.web; import java.util.List; import java.util.Map; import org.apache.struts2.ServletActionContext; import com.bc.bean.InformationParentSheet; import com.bc.dao.impl.daoImpl; import com.bc.service.impl.userServiceImpl; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class ListInfoAction extends ActionSupport { private userServiceImpl userService; private daoImpl dao; private List list; public daoImpl getDao() { return dao; } public void setDao(daoImpl dao) { this.dao = dao; } public userServiceImpl getUserService() { return userService; } public void setUserService(userServiceImpl userService) { this.userService = userService; } public List getList() { return list; } public void setList(List list) { this.list = list; } @SuppressWarnings("unchecked") @Override public String execute() throws Exception { // TODO Auto-generated method stub list=userService.pageInfo(1); return SUCCESS; } }
2.struts.xml
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name = "struts.custom.i18n.resources" value = "messageResoure_zh_CN"/> <constant name="struts.ui.theme" value="simple" /> <constant name="struts.multipart.maxSize" value="41943040" /> <constant name="struts.action.extension" value="action,do" /> <package name="user" extends="struts-default" > <action name="listInfo" class="ListInfoAction"> <result>/NewsList.jsp</result> </action> </package> </struts>
3.jsp页面显示
<body leftmargin="0" rightmargin="0" topmargin="0" onkeydown="if(event.keyCode==27) return false;"> <div id="popLayer" style="position: absolute; z-index: 1000;" class="cPopText"></div> <form action="ProductDeleteMultiple.jsp" name="formDelete" method="post" target="detail"> <table class="tableborder" align="center" cellpadding="3" cellspacing="1" width="99%" width="50%"> <tbody> <tr class="header"> <td align="center" width="7%"> <a href="isRec.action">是否推荐</a> </td> <td align="center" width="7%"> <a href="isHead.action">是否头条</a> </td> <td align="center" width="7%"> 所属类型 </td> <td align="center" width="16%"> 新闻标题 </td> <td align="center" width="14%"> 发布时间 </td> <td align="center" width="25%"> 新闻概要 </td> <td align="center" width="5%"> <a href="isPic.action">图片</a> </td> <td align="center" width="5%"> 备注 </td> <td align="center"> 操作 </td> </tr>
<s:iterator value="list" id="list"> <tr> <td class="altbg2" align="center"> <s:property value="ifRec"/> </td> <td class="altbg1" align="center"> <s:property value="ifHeadline"/> </td> <td class="altbg1" align="center"> <s:property value="informationParentSheet.ipName"/> </td> <td class="altbg1" align="center"> <s:property value="ifTitle"/> </td> <td class="altbg1" align="center"> <s:date name="ifPtTime" format="yyyy-MM-dd HH:mm"/> </td> <td class="altbg1" align="center"> <s:property value="ifSummary"/> </td> <td class="altbg1" align="center"> <s:if test=" #list.ifPicture != null"> <img width="60px" height="60px" src ='${pageContext.request.contextPath}/UploadImages/<s:property value ="ifPicture"/>'/> </s:if> </td> <td class="altbg1" align="center"> <s:property value="ifRemark"/> </td> <td class="altbg1" align="center"> <s:a href="removeInfo.action?is.ifId=%{#list.ifId}" onclick="return confirm('确定要删除该条新闻吗?')">删除</s:a> <s:a href="updatePInfo.action?is.ifId=%{#list.ifId}">修改</s:a> <s:a href="updateRecNews.action?type=isRec&&is.ifId=%{#list.ifId}&&ipId=%{#list.informationParentSheet.ipId}" onclick="return confirm('确定设置为推荐新闻?')">设为推荐</s:a> <s:a href="updateHeadline.action?type=isHeadline&&is.ifId=%{#list.ifId}&&ipId=%{#list.informationParentSheet.ipId}&&thePicture=%{#list.ifPicture}" onclick="return confirm('确定设置为头条新闻?')">设为头条</s:a> </td> </tr> </s:iterator> </tbody> </table><br/><br/> <center> <s:if test="list==null"> 查无数据! </s:if> <a href="listInfo.action">首页</a> <a href="splitPage.action?page=<s:property value="userService.pageNum-1"/>">上一页</a> <a href="splitPage.action?page=<s:property value="userService.pageNum+1"/>">下一页</a> <a href="splitPage.action?page=<s:property value="userService.pagecount"/>">尾页</a><br/><br/> 第 <s:property value="userService.pageNum"/>/<s:property value="userService.pagecount"/> 页 共 <s:property value="userService.count"/> 条 </center> <a name="bottom"></a> </body>
4.说明:
如以下,value="ifRec" 为list下的属性名.另在action内的属性只要提供了get方法,也可以直接在传递的jsp中取.
<s:property value="ifRec"/>