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正常啊。不知道为什么这次怎么就显示不出来了。谢谢大家了
<!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正常啊。不知道为什么这次怎么就显示不出来了。谢谢大家了
解决方案 »
- 工作问题,请大哥大姐给个真诚的建议!
- struts2 手动验证 可以控制调用validate()方法的位置吗?
- quartz的使用问题
- 跪求高手指教一个关于struts2的问题....
- 【求救】ejb的jar包中有.java文件为什么?(使用的是jbuilder)
- [求助]请大家帮我看看这段SAX解析XML文件的代码
- java里有谁用过apache fop 来把xml等生成pdf文件,现在主要是连基本的中文字符显示都不行 ?????????????
- jsp如何在websphere中运行
- rmi在本机上和两台机子上运行需要什么大的改变吗(100分)
- 在Java中往数据库中添加一条记录之后,使用select @@IDENTITY进行查找添加的数据的标识列,查找不出来,这是为什么?
- java编程思想的一个例子!自己想不明白!
- extJs 传到后台的字符串成[object object]
<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>试下
页面编码最好用utf-8,免得乱码
2.你没读到数据.
3.你在页面显示的时候,也就是jsp上面写错了
${newList}没显示值。但是问题是,在action中,我request.put()的时候,确实是put进去了值了。为什么在jsp中就读不到了
public class NewsAction extends ActionSupport试试
终于发现哪有问题了。。原来是之前的get,set是要小写的。。
比如id属性,我写的是SetId(int id)
改成 setId(int id)即可。。
呵,之前一直不知道还有这个说道
<result name="n" type="默认是什么来着?">/index.jsp</result>
......