Property Tag
The property tag is a generic tag that is used to get the property of a value, which will default to the top of the stack if none is specified.
Add the following code snippet into the struts.xml file.
struts.xml
| <action name="propertyTag" class="net.roseindia.propertyTag"> <result>/pages/genericTags/propertyTag.jsp</result> </action> |
Create an action class as shown:
propertyTag.java
package net.roseindia; |
Create a bean class "companyName" as shown:
companyName.java
package net.roseindia; |
Create a jsp using the tags.
<s:property value="%{name}" /> it prints the result of myBean's getMyBeanProperty() method.
<s:property value="name" default="Default Value" /> it prints the result of companyName's getName() method and if it is null, print 'a default value' instead.
propertyTag.jsp
<%@ taglib prefix="s" uri="/struts-tags" %> |
Output of the propertyTag.jsp:


本文介绍如何使用Struts2中的PropertyTag来获取并显示JavaBean属性值的方法。通过具体的代码示例展示了如何配置Action、创建JavaBean以及使用JSP页面来呈现数据。
1630

被折叠的 条评论
为什么被折叠?



