struts2中的下拉列表 [英] Drop down list in struts2

查看:30
本文介绍了struts2中的下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从数据库填充struts2网页中的ddropdown列表.下拉菜单项将从数据库中取出.

How to populate ddropdown list in a web page in struts2 from database. The items of the drop down will be taken from database.

推荐答案

struts2 中创建列表,我们可以使用implement Preparable.

For creating list in struts2, we can use implement Preparable.

public class CountryListAction extends ActionSupport implements Preparable {

 private List<String> country;
 getters and setters 

 public String prepareCountryList() throws Exception{

  country=new ArrayList<String>();
  country=fill country from database;

 }

 public String countryList() throws Exception{
  return SUCCESS;
 }

} 

对于jsp,使用:

<s:select label="Select Country"
   name="country"
   headerValue="Select Country"
   list="%{country}"
/>

Preparable 接口将在调用 countryList 之前调用 prepareCountryList 方法,并且将预填充 jsp.您可以在 struts2 中使用单一方法填充尽可能多的下拉列表.

Preparable interface will call prepareCountryList method before calling countryList and jsp will be prepopulated. You can populate as many drop down list using single method in struts2.

这篇关于struts2中的下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆