简体   繁体   English

从jsp调用动作方法

[英]calling an action method from a jsp

Simply..I need to know whether these list attributes are doing same job or not. 简单..我需要知道这些列表属性是否在做相同的工作。

<s:select name="city" label="City" list="cities" listKey="id" listValue="name" />

and

<s:select name="city" label="City" list="%{getCities()}" listKey="id" listValue="name" />

can we invoke action methods like above,If 'yes' what is the correct way to do that? 我们可以调用上面的动作方法吗?如果是,正确的方法是什么?

thanks, 谢谢,

list="cities" and list="%{getCities()}" both are exactly same. list="cities"list="%{getCities()}"完全相同。 Both calls getter of List<City> cities in action class to read value from valuestack . 两者都在操作类中调用List<City> cities getter来从valuestack读取值。

Both will throw an error if getter would be removed. 如果将删除getter,两者都将引发错误。

1. <s:select name="city" label="City" list="cities[0]" listKey="id" listValue="name" />

is evaluated to 被评估为

a. <s:select name="city" label="City" list="%{cities[0]}" listKey="id" listValue="name" />

b. <s:select name="city" label="City" list="%{getCities().get(0)}" listKey="id" listValue="name" />

1, a & b are same because % forces OGNL evaluation. 1,a和b相同,因为%强制执行OGNL评估。 that will query stack for particular property. 将查询堆栈的特定属性。

OGNL supports collections, that's why we can use this three. OGNL支持集合,因此我们可以使用这三个。

We call actions when we use particular need. 当我们使用特殊需求时,我们称之为行动。

For Example 例如

 <s:url id="databaseList" action="fetch-citynames" />
 <sd:autocompleter key="search"
     href="%{databaseList}" name="searchText" />

Here fetch-citynames return json list. 在这里, fetch-citynames返回json列表。

Also see this link 另请参阅此链接

Actually I read from here 其实我是从这里读的

OGNL

The principal reason is because %{} syntax is used to force OGNL evaluation where Struts would otherwise be treating the value as a String literal. 主要原因是因为使用%{}语法强制进行OGNL评估,否则Struts会将其视为字符串文字。

For example, 例如,

  <s:property value="name" />

will look for a name property in the value stack ie is a value retrieved by calling getName(). 将在值堆栈中查找名称属性,即通过调用getName()检索的值。

If you wanted to force it to use literal value "name", you will need to use the %{} syntax - 如果您想强制其使用文字值“ name”,则需要使用%{}语法-

 <s:property value="%{'name'}" />

But in the case of <s:select list="" /> it uses OGNL Collection Construction 但是对于<s:select list="" />它使用OGNL集合构造

Here is how OGNL call methods.. See here 下面是OGNL调用的方法。请参见这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM