1

我想为我的应用程序的某些类应用分页,其中我使用的是 spring、struts2 和 hibernate。在这里,我从welcome.jsp 文件中调用动作类。它有以下代码:

<s:form action="marketing/allCountry.action">  
         <s:submit value="Click"></s:submit>  
         </s:form>  

现在我allCountry.action的java类有以下代码:

public String executeAction() throws Exception {
        try {
            countryList = new ArrayList<Country>();
            countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
            System.out.println("countryList = "+countryList);
            return ActionSupport.SUCCESS;

        } catch (Exception ex) {
            return ActionSupport.ERROR;
        }
}

它正确地获取数据,我通过打印 countryList 对象确认。但现在我从 重定向SUCCESScountry.jsp。的代码country.jsp是:

<display:table list="countryList" requestURI="CountryAllAction" pagesize="3">
    <display:column property="id" title="ID" />
    <display:column property="name" />
</display:table>

现在在执行我的应用程序时,我遇到了运行时错误,例如:

javax.servlet.ServletException:javax.servlet.ServletException:异常:[.LookupUtil] 在对象类型“java.lang.String”中查找属性“id”时出错。原因:未知属性 'id'

此类错误的解决方案是什么?

4

5 回答 5

2

您需要在您的操作中为您的 countryList 设置一个吸气剂。

List<Country> countryList = new ArrayList<Country>();

public String executeAction() throws Exception {
  try {
     countryList = this.countrySecurityProcessor.findByAll(0, null, null, null, null, false, false, null, null, null, null, 0);
     System.out.println("countryList = "+countryList);
     return ActionSupport.SUCCESS;

  } catch (Exception ex) {
     return ActionSupport.ERROR;
  }

}

public List<Country> getCountryList() {
  return countryList;
}
于 2009-04-22T16:27:12.247 回答
0

我对 Struts2 不熟悉,但似乎 DisplayTag 在任何范围内都找不到您的 countryList。

我没有看到您将 countryList 放入 from 或 request 中。如果我不正确,您可能需要指定表单名称,例如 <display:table list="${yourStrutsFormName.countryList}" ...

于 2009-04-22T16:22:31.227 回答
0

您需要使 DisplayTag 可以使用“countryList”,例如通过执行以下操作:

   request.setAttribute("countryList", countryList);

在你的行动中(除非有更聪明的 Struts2 方法来做到这一点)。我认为您可以通过实现ServletRequestAware来掌握您的操作中的请求

您还需要确保您的 Country 类具有 id 和 name 属性。

于 2009-04-23T07:16:26.197 回答
0

使用以下代码。而不是列表属性使用名称属性。

<display:table name="countryList" requestURI="CountryAllAction" pagesize="3">
 <display:column property="id" title="ID" />
 <display:column property="name" />
</display:table>
于 2009-07-01T11:05:24.143 回答
0

你不需要做任何事情,只需在显示标签名称中使用列表变量,即

<display:table name="yourListnameinaction">

</display>
于 2009-08-25T06:56:49.687 回答