ITeye博客

JSP中得到action中属性的方法

xu520 · 2012-08-27 19:51 · Markdown

1、例如action中有一个pageDAO对象,该对象有一个int型的currentPage属性,可以在jsp中这样

得到currentPage的值:

//注意,action中要有pageDAO对象的get方法,属性currentPage也要有get方法。

int test=(Integer)request.getAttribute("pageDAO.currentPage");

2、EL表达式:${pageDAO.currentPage}

3、使用struts2的标签

<s:property value="pageDAO.currentPage"/>

Action中有一个属性 List<Person> persons;(Person是一个类 有name和age属性)现在通过struts.xml配置 转向到show.jsp问题就是:在show.jsp取得persons中的name和age

1)action定义getPersons()

2)Person中定义getName()和getAge()

3):<s:iterator id="u" value="persons">

<s:property value='#u.getName()'/>

<s:property value='#u.getAge()'/>

struts2还需这么传值吗?

把要传的值定义为action的成员变量,为其建立set 、get方法,在action中为其赋值;

然后在jsp中直接引用其名即可。

例如:action中的book在jsp中引用:<s:property value="book.bookname" />

</s:iterator>

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。