如何使用< bean:write>标记在strut 1.2中? [英] how to use <bean:write > tag in strut 1.2?

查看:114
本文介绍了如何使用< bean:write>标记在strut 1.2中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在Struts 1.2中使用<bean:write>标记.

name属性中,必须使用什么值? Bean名称是您的财产名称吗?

解决方案

用于 <bean:write> :

指定要访问其属性的Bean的属性名称 检索由 property 指定的值(如果已指定).如果财产 未指定,则将呈现此bean本身的值.

本质上,如果您有JavaBean(带有getter和setter),

Person person = new Person;
request.setAttribute("person", person);

通过设置<bean:write name="person" property="age" />,您告诉Struts首先从PageContext范围中找到person对象 first .如果找不到,则依次为requestsessionapplication范围.

property="age"属性(来自<bean:write />标记)将随后从Person对象调用吸气剂方法getAge()(与bean上是否存在名为age的实例变量无关).

希望这会有所帮助.

How to Use <bean:write> tag in Struts 1.2.

In name attribute, what value have to be used? Is bean name your property name?

解决方案

Javadoc for <bean:write>:

Specifies the attribute name of the bean whose property is accessed to retrieve the value specified by property (if specified). If property is not specified, the value of this bean itself will be rendered.

In essence, if you have a JavaBean (with getters and setters),

Person person = new Person;
request.setAttribute("person", person);

by setting <bean:write name="person" property="age" />, you're telling Struts to first find person object first from PageContext scope. If not found, then request, then session, then application scope.

The property="age" attribute (from <bean:write /> tag), will then call the getter method getAge() from the Person object (irrespective of whether there's an instance variable called age on the bean).

Hope this helps.

这篇关于如何使用&lt; bean:write&gt;标记在strut 1.2中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆