struts.xml:<?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>    action: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";
}
}index.jsp<%@ 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正常啊。不知道为什么这次怎么就显示不出来了。谢谢大家了

解决方案 »

  1.   

    <s:iterator value="list" id="list">
        <li>
            <em><s:property value="date"/></em>
            <a href="ShowNews.jsp?id=<s:property value='id'/>" target="_blank"><s:property value="title"/></a>
        </li>    
    </s:iterator>试下
      

  2.   

    首先先用el表达式看看有没有值,在页面的body里面${newsList},有值的话就好办。
    页面编码最好用utf-8,免得乱码
      

  3.   

      1.要就是你没数据.
      2.你没读到数据.
      3.你在页面显示的时候,也就是jsp上面写错了
      

  4.   


    ${newList}没显示值。但是问题是,在action中,我request.put()的时候,确实是put进去了值了。为什么在jsp中就读不到了
      

  5.   

    Action里面写
    public class NewsAction extends ActionSupport试试
      

  6.   


    终于发现哪有问题了。。原来是之前的get,set是要小写的。。
    比如id属性,我写的是SetId(int id)
    改成 setId(int id)即可。。
    呵,之前一直不知道还有这个说道
      

  7.   

    用session试试,估计是请求转发与重定向的问题
    <result name="n" type="默认是什么来着?">/index.jsp</result>
    ......