tag 'select', field 'list', name 'protype': The requested list key 'proList' cou

1.页面代码

--------------------------------------------------------------------------------------------------------------------------------------------------

<body>
<div id="glo" style="width: 200px">
<h3>
select2
</h3>
<s:form action="../select2.action">


<s:select list="userlist" listKey="id" listValue="firstname"></s:select>
</s:form>
</div>

</body>

--------------------------------------------------------------------------------------------------------------------------------------------------

2.pojo 类





private Integer id;
private String firstname;
private String lastname;
private String password;
private String description;

public User(){}
public User(Integer id,String lastname){
this.id=id;
this.lastname=lastname;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
private int age;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}
public String getLastname() {
return lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}

--------------------------------------------------------------------------------------------------------------------------------------------------





3.action 类 java代码

--------------------------------------------------------------------------------------------------------------------------------------------------

/***
*
*
* 组件学习
* @return
*/
private User user;
private UserService service;
private String userType;
private String username;
private List<User> userlist;
private final static Logger log=Logger.getLogger(Component.class);





public List<User> getUserlist() {
return userlist;
}


public void setUserlist(List<User> userlist) {
this.userlist = userlist;
}


public static Logger getLog() {
return log;
}



public User getUser() {
return user;
}


public void setUser(User user) {
this.user = user;
}



//select
public String select2(){

List<User> userlist=new ArrayList<User>();
//从dao查出所有用户
userlist=service.findAll();
log.info("userlist's value:"+userlist);

return "back";
}

--------------------------------------------------------------------------------------------------------------------------------------------------

4.struts2.xml



<action name="select2" class="select2Action" method="select2">
<result name="back">/components/select2.jsp</result>
</action>

--------------------------------------------------------------------------------------------------------------------------------------------------



页面报错

--------------------------------------------------------------------------------------------------------------------------------------------------

tag 'select', field 'list': The requested list key 'userlist' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
at org.apache.struts2.components.Component.fieldError(Component.java:231)
at org.apache.struts2.components.Component.findValue(Component.java:293)
at org.apache.struts2.components.ListUIBean.evaluateExtraParams(ListUIBean.java:79)
at org.apache.struts2.components.Select.evaluateExtraParams(Select.java:99)
at org.apache.struts2.components.UIBean.evaluateParams(UIBean.java:780)
at org.apache.struts2.components.UIBean.end(UIBean.java:481)
at org.apache.struts2.views.jsp.ComponentTagSupport.doEndTag(ComponentTagSupport.java:43)
at org.apache.jsp.components.select2_jsp._jspx_meth_s_005fselect_005f0(select2_jsp.java:155)
at org.apache.jsp.components.select2_jsp._jspx_meth_s_005fform_005f0(select2_jsp.java:120)
at org.apache.jsp.components.select2_jsp._jspService(select2_jsp.java:79)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)

--------------------------------------------------------------------------------------------------------------------------------------------------



解决方法:分析原因,可能是list中值为空,userlist=service.findAll();此行代码没有setUserList(),导致属性userlist再页面上值为空,如下修改action类



//select
public String select2(){

List<User> userlist=new ArrayList<User>();
//从dao查出所有用户
userlist=service.findAll();
log.info("userlist's value:"+userlist);
//设置属性值
this.setUserlist(userlist);
return "back";
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值