【问题标题】:Weird and infuriating struts problem!奇怪而令人愤怒的支柱问题!
【发布时间】:2011-04-25 04:34:03
【问题描述】:

我不断收到以下 struts 错误:

描述服务器遇到了一个内部错误(),导致它无法完成这个请求。

异常

org.apache.jasper.JasperException: tag 'select', field 'list', name 'dept': The requested list key 'deptList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]

。 . .

这是我的 .jsp 文件中的代码:

         <s:select name="dept" list="deptList" listKey="deptId" listValue="deptString" headerKey="0" headerValue="Select a Department"
         label="Select Department" />

这是我的操作文件中的代码(我通过调试验证它返回正确的值):

          @Override
          public String execute() throws Exception {
             org.springframework.web.context.ContextLoaderListener c = new                  org.springframework.web.context.ContextLoaderListener();
          EmployeeDao dao = (EmployeeDao) ContextLoader.getCurrentWebApplicationContext().getBean("employeeDao");                 
          deptList=dao.getDeptsList();                    
          //Employee employee=dao.getEmployeeforHRList(getLname(), getFname());  
          return SUCCESS;
          }

这是我的数据访问文件中的代码:

          public List<Department> getDeptsList(){
            String query = "from Department";        
            List<Department> departments = getSession().createQuery(query).list();
            return departments;
          }

【问题讨论】:

  • 我在执行方法中没有看到任何将获取的集合设置为表单 bean 的代码?
  • 这是我的 struts.xml 文件中与此相关的部分:
  • 对不起。 . .点击错误按钮: human_res. jsphuman_res.jsphuman_res.jsphuman_res.jsp 我真的需要一个仅用于下拉列表的表单吗?没有输入的数据只显示从数据库中。
  • 你的jsp如何找到数据?
  • 猜猜我发现了问题所在。 . .我必须为下拉菜单编写一个表单 bean :) 我的印象是我在 struts.xml 文件中的上述代码会做到这一点。感谢您的提醒!

标签: java hibernate jsp struts2


【解决方案1】:

需要将列表设置成formBean

您正在从 jsp 中查找集合,并且您没有在 FormBean 中设置该集合,或者您也可以使用适当的 EL 在请求/页面/会话/应用程序范围内设置它。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-29
    • 1970-01-01
    • 1970-01-01
    • 2011-04-28
    • 2014-09-30
    • 1970-01-01
    • 2023-03-24
    • 2019-07-26
    相关资源
    最近更新 更多