日期:2014-05-18  浏览次数:20682 次

为什么在后台action中传值到前台,得到的值为null(Structs开发的)
Action类:
public   class   DynaStyleAction   extends   Action   {

public   ActionForward   execute(ActionMapping   mapping,   ActionForm   form,
HttpServletRequest   request,   HttpServletResponse   response)   {
//   TODO   Auto-generated   method   stub
List   weekWeather   =   DataSources.getWeekForecast();
request.setAttribute( "weekWeather ",weekWeather);

return   mapping.findForward( "display ");
}
}

JSP页面
<%@   page   contentType= "text/html;charset=UTF-8 "   language= "java "   %>

<%@   taglib   uri= "http://java.sun.com/jsp/jstl/core "   prefix= "c "   %>

<html>
<head>
<title> Dynamic   Style </title>
<style>
/*   Even   row   */
.row1   {background-color:orange;}

/*   Odd   row   */
.row0   {background-color:yellow;}

/*   Title   row   */
.title   {background-color:blue;color:white;text-align:center;}
</style>
</head>
<body>
<%

out.print(request.getAttribute( "weekWeather "));

  %>
<div   align= "center ">
<h3> Dynamic   Style </h3>
<table   width= "300 ">
<tr   class= "title ">
<th   width= "100 "> Day </th>
<th> Rain   Percent </th>
</tr>
<c:forEach   var= "day "   items= "${weekWeather} "   varStatus= "loop ">
<tr   class= "row${loop.count%2} ">
<td   align= "left "> ${day.item} </td>
<td   align= "right "> ${day.percent}% </td>
</tr>
</c:forEach>
</table>
</div>
</body>
</html>

求高手帮忙!

------解决方案--------------------
List weekWeather = DataSources.getWeekForecast();
这个是不是能够的到呢?你自己试试这里是不是出问题了
------解决方案--------------------
那就证明List weekWeather = DataSources.getWeekForecast();的list就没有得到值,测试一下 if(weekWeather==null)
{
System.out.println( "null ");
}
else
{
System.out.println( "ok ");
}
如果是ok那就看你的getWeekForecast()方法把有问题