读书人

Struts中的Action施用request不当导致

发布时间: 2012-11-09 10:18:47 作者: rapoo

Struts中的Action使用request不当导致前端无法找到相应的属性

在使用Struts时,我们经常在Action中向request存储结果有两种方式,一种是直接使用setAttribute()方法,一种是先调用request的getsession()方法后,然后再使用setAttribute()方法。
开始由于不知道这两者的差别,我使用了后一种方式,即request.getSession().setAttribute(),但是这样在页面中使用logic:present时,如:

1Struts中的Action施用request不当导致前端无法找到相应的属性??????????<logic:present?name="Customers"?scope="request">
2Struts中的Action施用request不当导致前端无法找到相应的属性??????????????<logic:iterate?id="customer"?name="Customers"?scope="request">
3Struts中的Action施用request不当导致前端无法找到相应的属性Struts中的Action施用request不当导致前端无法找到相应的属性??????????????????<tr><td>$Struts中的Action施用request不当导致前端无法找到相应的属性{customer.cname?}</td><td>$Struts中的Action施用request不当导致前端无法找到相应的属性{customer.code?}</td></tr>
4Struts中的Action施用request不当导致前端无法找到相应的属性??????????????</logic:iterate>
5Struts中的Action施用request不当导致前端无法找到相应的属性??????????</logic:present>


如果定义scope为request.程序是始终都找不相应attribute的。
因为前一种方式是在request的范围内设置Attribute,而后一种方式中的getSession()是获取当前的session,这样设置Attribute当然是在session范围内设置Attribute,在前台当然是找不到相应的属性的。

读书人网 >软件架构设计

热点推荐