在做Struts的时候,我在SearchAction中将查找的结果(List类型的变量)保存在request中,然后再跳转。但是我在跳转的目标页面却找不到这个变量,提示说不存在。请问一下:为什么会出现这种情况?
代码如下:
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
{
       .....
       List<Tel> list = teldao.searchByCondition(searchForm.getCondition(), pid);
       request.setAttribute("result", list);
       return mapping.findForward(ConstantVar.show_result); 
}
目标页面:
<logic:iterate id="tel" name="result">
  <tr>
<td>
<bean:write name="tel" property="id" />
</td>
<td>
<bean:write name="tel" property="name" />
</td>
<td>
<bean:write name="tel" property="telphone" />
</td>
<td>
<bean:write name="tel" property="address" />
</td>
  </tr>
</logic:iterate>    

解决方案 »

  1.   

    搞个<logic:present></logic:present>测试下
    应该是存在的 估计是你遍历的时候出现问题
      

  2.   

    断点跟进action看看list到底有没有东西
      

  3.   

    <logic:present name="result" scope="request"><logic:iterate id="tel" name="result">
       <tr>
    <td>
    <bean:write name="tel" property="id" />
    </td>
    <td>
    <bean:write name="tel" property="name" />
    </td>
    <td>
    <bean:write name="tel" property="telphone" />
    </td>
    <td>
    <bean:write name="tel" property="address" />
    </td>
       </tr>
    </logic:iterate>     </logic:present>
      

  4.   

    在action中打断点,看到底  list中存入值了没有?
      

  5.   

    哈哈,终于找到原因了,是由于重定向没能取得request范围的值。谢谢各位啦