如何通过属性文件访问Struts框架上的数组列表的值 [英] how access value of array list on Struts framework by properties file

查看:67
本文介绍了如何通过属性文件访问Struts框架上的数组列表的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

arraylist.add(new ListItem("Activity1", "ActivityName1"));

假定ActivityName1值存储在属性文件中以提供语言环境功能.

suppose ActivityName1 value store in properties file to provide locale feature.

现在我如何使用Struts访问与jsp上的ActivityName1值关联的Activity1键的值(ActivityName1对应于属性文件值).

now how can i access the value of Activity1 key that associate to ActivityName1 value on jsp ( ActivityName1 corresponds to a properties file value) by using Struts.

我想通过使用Struts框架中的Activity1键来找到存储在属性文件中的ActivityName1值.

i want to find the ActivityName1 value that store in properties file by using the Activity1 key in Struts framework.

推荐答案

例如,如果您的struts属性文件定义如下,

For example if your struts property file defined as follows,

ActivityName1=Activity Name 1 Value in English

只需在JSP文件内部访问即可,如下所示,

inside the JSP file simply you can access it as follows,

<s:label value="%{getText('ActivityName1')}"/>

要遍历JSP文件中的ArrayList,可以使用标记.以下是一个简单的示例,

And to iterate through your ArrayList in the JSP file you can use the tag. And following is an simple example,

ListItem bean类

ListItem bean class

public class ListItem {
    private String listKey;
    private String listValue;
    // getters and setters
}

内部动作类

// defined in action calss with getters and setters
private List<ListItem> listItems;

// inside method in action class
listItems.add(new ListItem("Activity1","ActivityName1"));
......

内部JSP文件

<s:iterator value="listItems">
    <s:property value="%{getText('listKey')}"/>
    <s:property value="%{getText('listValue')}"/>
</s:iterator> 

结合这些技巧,我认为您会找到解决问题的方法....

By combining these tips I think you will find a solution for your question....

这篇关于如何通过属性文件访问Struts框架上的数组列表的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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