日期:2014-05-19 浏览次数:20940 次
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="Type" extends="struts-default">
<!-- 得到指定类型的所有新闻 -->
<action name="GetNewsList" class="Action.NewsAction" method="GetNewsList">
<result name="success">/index.jsp</result>
</action>
</package>
</struts>
package Action;
import java.util.ArrayList;
import java.util.Map;
import Service.NewsService;
import Vo.News;
import com.opensymphony.xwork2.ActionContext;
public class NewsAction {
private ArrayList<News> list = new ArrayList<News>();
private int typeId;
public ArrayList<News> getNewsList(){
return this.list;
}
public void setNewsList(ArrayList<News> temp){
this.list = temp;
}
public void setTypeId(int typeId){
this.typeId = typeId;
}
public int getTypeId(){
return this.typeId;
}
public String GetNewsList(){
NewsService service = new NewsService();
//System.out.println("类型号"+getTypeId());
list = service.GetNewsList(getTypeId());
//System.out.println(list.size()); // 打印出来可以看到list中已经有内容了
Map request = (Map) ActionContext.getContext().get("request");
request.put("newsList", list);
return "success";
}
}
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<html>
<head></head>
<body>
<s:action name="GetNewsList" >
<s:param name="typeId">1</s:param>
</s:action>
<s:iterator value="#request.newsList" id="list">
<li>
<em><s:property value="#list.date"/></em>
<a href="ShowNews.jsp?id=<s:property value='#list.id'/>" target="_blank"><s:property value="#list.title"/></a>
</li>
</s:iterator>
</body>
</html>
麻烦大家指点下,我之前用类似的方法显示另一个list正常啊。不知道为什么这次怎么就显示不出来了。谢谢大家了