struts2 select标签使用问题
我的开发环境是struts2+spring+hibernate.我的页面上有一个<select>如何才能让下拉列表动态得到数据库中的值?部分代码如下:struts.xml...
我的开发环境是struts2+spring+hibernate.我的页面上有一个<select>如何才能让下拉列表动态得到数据库中的值?部分代码如下:
struts.xml代码:
<package name="category" namespace="/" extends="struts-default"> <action name="categoryFind" class="categoryFindAllAction">
<result name="success">/xxx.jsp</result>
</action>
</package>
applicationContext.xml代码如下:
<bean id="categoryFindAllAction"class="xxx.CategoryFindAllAction">
<property name="categoryService" ref="categoryService"></property>
</bean>
DAO实现类:
public List<Category> findAll(Category category){
String hql = "from Category category order by category.cid asc";
List<Category> list = new ArrayList<Category>();
try{
list = this.getHibernateTemplate().find(hql);
}catch(DataAccessException e){
e.toString();
e.printStackTrace();
}
return list;
}
service实现类:
public List<Category> findAll(Category category) {
List<Category> list = new ArrayList<Category>();
try{
list = this.categoryDao.findAll(category);
}catch(RuntimeException e){
e.toString();
e.printStackTrace();
}
return list;
}
ACTION代码:
public String execute() throws Exception{
try{
list = this.categoryService.findAll(category);
Map map = new HashMap();
for (Category c : list){
map.put("cid", c.getCid());
map.put("cname", c.getCategoryName());
}
catList.add((HashMap) map);
}catch(Exception e){
e.toString();
e.printStackTrace();
}
return SUCCESS;
}
JSP代码:
<s:action name="categoryFind" id="categoryFind"></s:action>
<s:select list="#categoryFind.catList" headerKey="0" headerValue="请选择分类" listKey="cid" listValue="cname" value="category.categoryName" label="所属类别"></s:select>
以下为页面运行后,TOMCAT提示的异常:
严重: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list': The requested list key '#categoryFind.catList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
我在网上查了很长时间了,真不知道自己错哪儿了!!请大家帮忙看看... 展开
struts.xml代码:
<package name="category" namespace="/" extends="struts-default"> <action name="categoryFind" class="categoryFindAllAction">
<result name="success">/xxx.jsp</result>
</action>
</package>
applicationContext.xml代码如下:
<bean id="categoryFindAllAction"class="xxx.CategoryFindAllAction">
<property name="categoryService" ref="categoryService"></property>
</bean>
DAO实现类:
public List<Category> findAll(Category category){
String hql = "from Category category order by category.cid asc";
List<Category> list = new ArrayList<Category>();
try{
list = this.getHibernateTemplate().find(hql);
}catch(DataAccessException e){
e.toString();
e.printStackTrace();
}
return list;
}
service实现类:
public List<Category> findAll(Category category) {
List<Category> list = new ArrayList<Category>();
try{
list = this.categoryDao.findAll(category);
}catch(RuntimeException e){
e.toString();
e.printStackTrace();
}
return list;
}
ACTION代码:
public String execute() throws Exception{
try{
list = this.categoryService.findAll(category);
Map map = new HashMap();
for (Category c : list){
map.put("cid", c.getCid());
map.put("cname", c.getCategoryName());
}
catList.add((HashMap) map);
}catch(Exception e){
e.toString();
e.printStackTrace();
}
return SUCCESS;
}
JSP代码:
<s:action name="categoryFind" id="categoryFind"></s:action>
<s:select list="#categoryFind.catList" headerKey="0" headerValue="请选择分类" listKey="cid" listValue="cname" value="category.categoryName" label="所属类别"></s:select>
以下为页面运行后,TOMCAT提示的异常:
严重: Servlet.service() for servlet jsp threw exception
tag 'select', field 'list': The requested list key '#categoryFind.catList' could not be resolved as a collection/array/map/enumeration/iterator type. Example: people or people.{name} - [unknown location]
我在网上查了很长时间了,真不知道自己错哪儿了!!请大家帮忙看看... 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询