Action中的list和Jsp中的<s:select>标签怎么进行传值
我的Action从数据库中取值,存在一个List里面,如List<**Bean>,测试有值,现在想把这个List传到Jsp页面的<s:select>标签中,总报错。Act...
我的Action从数据库中取值,存在一个List里面,如List<**Bean>,测试有值,现在想把这个List传到Jsp页面的<s:select>标签中,总报错。
Action主要代码如下:List<DptSelectBean> selectBeanList =new ArrayList<DptSelectBean>();
selectBeanList = accountAddService.dptSelect();
setSelectBeanList(selectBeanList);
Jsp主要代码如下:
<s:select list="selectBeanList" listkey="departmentID" listvalue="departmentName" name="accountInputBean.departmentName" headerkey="departmentID" headervalue="请选择" multiple="true">
</s:select>
DptSelectBean代码如下
package dl.chamstone.com.cn.bean.account;
import dl.chamstone.com.cn.bean.BeanObject;
public class DptSelectBean implements BeanObject {
private static final long serialVersionUID = -2867242004393508889L;
private Integer departmentID;
private String departmentName;
/**
* @return the departmentID
*/
public Integer getDepartmentID() {
return departmentID;
}
/**
* @param departmentID the departmentID to set
*/
public void setDepartmentID(Integer departmentID) {
this.departmentID = departmentID;
}
/**
* @return the departmentName
*/
public String getDepartmentName() {
return departmentName;
}
/**
* @param departmentName the departmentName to set
*/
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
/** default constructor */
public DptSelectBean() {
}
}
报错信息:页面上报错:Struts Problem Report
Struts has detected an unhandled exception:
Messages: Stream closed
File: org/apache/jasper/runtime/JspWriterImpl.java
Line number: 204
--------------------------------------------------------------------------------
Stacktraces
java.io.IOException: Stream closed
Eclipes中报错:org.apache.jasper.JasperException: tag 'select', field 'list', name 'accountInputBean.departmentName': The requested list key 'selectBeanList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
哪位高人帮忙分析下,谢谢! 展开
Action主要代码如下:List<DptSelectBean> selectBeanList =new ArrayList<DptSelectBean>();
selectBeanList = accountAddService.dptSelect();
setSelectBeanList(selectBeanList);
Jsp主要代码如下:
<s:select list="selectBeanList" listkey="departmentID" listvalue="departmentName" name="accountInputBean.departmentName" headerkey="departmentID" headervalue="请选择" multiple="true">
</s:select>
DptSelectBean代码如下
package dl.chamstone.com.cn.bean.account;
import dl.chamstone.com.cn.bean.BeanObject;
public class DptSelectBean implements BeanObject {
private static final long serialVersionUID = -2867242004393508889L;
private Integer departmentID;
private String departmentName;
/**
* @return the departmentID
*/
public Integer getDepartmentID() {
return departmentID;
}
/**
* @param departmentID the departmentID to set
*/
public void setDepartmentID(Integer departmentID) {
this.departmentID = departmentID;
}
/**
* @return the departmentName
*/
public String getDepartmentName() {
return departmentName;
}
/**
* @param departmentName the departmentName to set
*/
public void setDepartmentName(String departmentName) {
this.departmentName = departmentName;
}
/** default constructor */
public DptSelectBean() {
}
}
报错信息:页面上报错:Struts Problem Report
Struts has detected an unhandled exception:
Messages: Stream closed
File: org/apache/jasper/runtime/JspWriterImpl.java
Line number: 204
--------------------------------------------------------------------------------
Stacktraces
java.io.IOException: Stream closed
Eclipes中报错:org.apache.jasper.JasperException: tag 'select', field 'list', name 'accountInputBean.departmentName': The requested list key 'selectBeanList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
哪位高人帮忙分析下,谢谢! 展开
展开全部
1.很有可能你查出来的是空,所以没法循环
2.我测试了下,改动下Action代码
List<DptSelectBean> selectBeanList =new ArrayList<DptSelectBean>();
public List<DptSelectBean> getSelectBeanList() {
return selectBeanList;
}
public void setSelectBeanList(List<DptSelectBean> selectBeanList) {
this.selectBeanList = selectBeanList;
}
@Override
public String execute() throws Exception {
// selectBeanList = accountAddService.dptSelect();
DptSelectBean d1=new DptSelectBean();
d1.setDepartmentID(1);
d1.setDepartmentName("a");
DptSelectBean d2=new DptSelectBean();
d2.setDepartmentName("b");
d2.setDepartmentID(2);
selectBeanList.add(d1);
selectBeanList.add(d2);
// setSelectBeanList(selectBeanList);
return SUCCESS;
}
没有任何问题
2.我测试了下,改动下Action代码
List<DptSelectBean> selectBeanList =new ArrayList<DptSelectBean>();
public List<DptSelectBean> getSelectBeanList() {
return selectBeanList;
}
public void setSelectBeanList(List<DptSelectBean> selectBeanList) {
this.selectBeanList = selectBeanList;
}
@Override
public String execute() throws Exception {
// selectBeanList = accountAddService.dptSelect();
DptSelectBean d1=new DptSelectBean();
d1.setDepartmentID(1);
d1.setDepartmentName("a");
DptSelectBean d2=new DptSelectBean();
d2.setDepartmentName("b");
d2.setDepartmentID(2);
selectBeanList.add(d1);
selectBeanList.add(d2);
// setSelectBeanList(selectBeanList);
return SUCCESS;
}
没有任何问题
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询