如何在struts中访问jsp标记?例如:
<s:select name="country" list="<%=countryList%>" headerKey="0" headerValue="Country"
label="Select your country" required="true"/>
例外:
消息: /jsp/index.jsp(35,2)根据TLD或标记文件中的属性指令,属性列表不接受任何表达式。countryList是ArrayList。
发布于 2012-03-01 09:03:04
异常很清楚地指明了原因,因为S2标记将不允许它内部的这个表达式。over标记需要一个List/ArrayList或任何集合列表作为数据源,并且构建在ONGL机制中将为您完成其余的工作。
您有一种干净的方法来实现这一点,使用名称countryList
在操作类中创建一个属性,该属性的数据类型应该为List/Map,并为该property.Fill提供一个getter和setter --该列表包含操作类中所需的数据。
行动类
public class MyAction extends ActionSupport{
private List<String> countryList;
// getter and setter for countryList
public String execute() throws Exception{
countryList=new ArrayList<String>();
// Add values to list
return SUCCESS;
}
}
现在,在您的JSP中,您需要做的全部工作如下
<s:select name="country" list="countryList" headerKey="0" headerValue="Country"
label="Select your country" required="true"/>
因此,当OGNL将此list="countryList"
作为数据源时,它将在操作类中查找名为getCountryList()的方法,并使用该数据填充select标记。
希望这能让你清楚地知道这是怎么回事。有关详情,请参阅正式文件
选择标签
发布于 2012-03-01 08:47:54
您不需要对列表使用java脚本。
您必须使用OGNL表达式。如果您的操作有一个getCountryList方法,那么您需要做的就是:
<s:select name="country" list="countryList" headerKey="0" headerValue="Country"
label="Select your country" required="true"/>
您应该搜索一些关于如何在struts中使用OGNL的文档。它真的很强大。
https://stackoverflow.com/questions/9512980
复制相似问题