这是action代码:
List<NewsForm> newsList; //存放action之间的提示信息
String actionMsg ;
public String listNews(){
if (actionMsg!=null)addActionMessage(java.net.URLDecoder.decode(actionMsg));
newsList = service.allNews();
return SUCCESS;
}这是JSP:<s:if test="newsList!=null">
<table border="1">
<tr align="center">
<td>
xxx <s:hidden name="news_detail"/>
</td>
<td>
xxxxx </td>
<td>
xxxxxx </td>
<td>
xxxxxxxxxxxx </td>
<td align="center" colspan=4>
操作
</td>
</tr>
<s:iterator id="row" value="newsList">
<tr align="center" >
<td ><s:property value="news_id"/></td>
<td ><s:property value="news_theme"/></td>
<td ><s:property value="news_author"/></td>
<td ><s:property value="news_date"/></td>
这是struts.xml:
<action name="news_*" class="com.xwxt.action.AllNewsAction" method="{1}">
<!-- 定义名为success的局部result,其结果类型为redirect-action -->
<result name="searchAll" type="redirectAction">
<param name="actionName">news_listNews</param>
<param name="actionMsg">${actionMsg}</param>
</result>
<!-- 定义名为success的局部result,其结果类型为默认的dispatcher -->
<result>/index.jsp</result>
List<NewsForm> newsList; //存放action之间的提示信息
String actionMsg ;
public String listNews(){
if (actionMsg!=null)addActionMessage(java.net.URLDecoder.decode(actionMsg));
newsList = service.allNews();
return SUCCESS;
}这是JSP:<s:if test="newsList!=null">
<table border="1">
<tr align="center">
<td>
xxx <s:hidden name="news_detail"/>
</td>
<td>
xxxxx </td>
<td>
xxxxxx </td>
<td>
xxxxxxxxxxxx </td>
<td align="center" colspan=4>
操作
</td>
</tr>
<s:iterator id="row" value="newsList">
<tr align="center" >
<td ><s:property value="news_id"/></td>
<td ><s:property value="news_theme"/></td>
<td ><s:property value="news_author"/></td>
<td ><s:property value="news_date"/></td>
这是struts.xml:
<action name="news_*" class="com.xwxt.action.AllNewsAction" method="{1}">
<!-- 定义名为success的局部result,其结果类型为redirect-action -->
<result name="searchAll" type="redirectAction">
<param name="actionName">news_listNews</param>
<param name="actionMsg">${actionMsg}</param>
</result>
<!-- 定义名为success的局部result,其结果类型为默认的dispatcher -->
<result>/index.jsp</result>
<s:if>下面全部空白,标题已经说了嘛,不显示
断点我测试过了,
newsList = service.allNews();有数据的,但是就是不能显示到JSP上,我在看看JSP是否写错了
<param name="actionName">news_listNews</param>
<param name="actionMsg">${actionMsg}</param>
</result>
你定义的跳转方法是,重定向,而且你没有把你的数据信息当参数传递过去啊。你只传递了一个msg~
<result name="searchAll" type="redirectAction">
不要用这种方式跳转。用chain,type="chain",这种跳转方式可以直接在第二个action中用第一个action里面的属性【有get/set】的参数。
asdfdasf
</s:if>看看出来不?先把问题简单化一下~
<tr align="center" >
<td ><s:property value="#news_id"/></td>
<td ><s:property value="#news_theme"/></td>
<td ><s:property value="#news_author"/></td>
<td ><s:property value="#news_date"/></td>
加上 # 试试
所以请教一下你,我也估计后台没有传来。你看我这些代码有问题么?还需要看哪些代码?断点跟到action方法里的 这句代码时 newsList = service.allNews();
newsList 里有从数据库select出的数据。
<tr align="center" >
<td >${new.news_id}</td>
你这里newsList = service.allNews();这个newsList有没有set/get方法?
return SUCCESS; 这里返回success后,你的xml中配置的返回index.jsp。那你的那个迭代的页面是不是index.jsp?
这不一样么。。我就是从c标签换到s表情的,我估计newsList没有穿过来。谁知道啊
<tr align="center" >
<td ><s:property value="#nl.news_id"/></td>你试试这样,但是我觉得这样跟你写的是一致的。而且,你看看你action中的list的size()!
这句话能进去吗?首先你要保证你的newList是有值的啊。。这个正确写法应该是这样把。
<s:if test="${newsList!=null}">
<s:if/>
现在应该就是newsList没有值,但是在action中我打了断点,显示有值啊,到JSP就怎么就没了,现在就是这个问题!
3.后台传递的有数据没
2.<s:if test="newsList!=null" name=""/> 执行了没
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> 像这样的。
然后把你的这个地方给修改下
<c:if test="newsList!=null">
这句话能进去吗?首先你要保证你的newList是有值的啊。。这个正确写法应该是这样把。
<c:if test="${newsList!=null}">
<c:if/> 循环的地方写成这样
<c:forEach var="item" items="${newsList}" varStatus="s" ><
<tr align="center" >
<td ><s:property value="${item.news_id}"/></td>
<td ><s:property value="${item.news_theme}"/></td>
<td ><s:property value="${item.news_author}"/></td>
<td ><s:property value="${item.news_date}"/></td>
<tr/>
</c:forEach>
页面当中可以这样判断吗?没见过呢,试下<s:if test="%{newsList!=null}">