s:select 在structs中的用法

1: 在jsp中写死了options的值, 注意,这时候list后面的"#"必不可少,而且非常重要

<s:select name="ecId" list="#{0:'NDS,1 EC,2 DB2',1:'NDS,4 EC,4 DB2'}" label="Select a EC Type" 
/>

 

2: 用hashmap来设置值:

在jsp中:

		
<s:select name="ecId" list="ecMap"
listKey="key"  listValue="value"  
headerKey="" headerValue="Select ecType"
label="Select a EC Type" 
/>

在java中:

		ecMap = new HashMap();
		ecMap.put(0, "NDS,1 EC,2 DB2");
		ecMap.put(1, "NDS,4 EC,4 DB2");

 

 

3: 用bean的list来设置值:

 

在jsp中:

 
<s:select name="ecId" list="ecTypeList"
listKey="id"  listValue="type"  
headerKey="" headerValue="Select ecType"
label="Select a EC Type" 
/> 

在java bean文件中设置属性:

        private String id;
	private String type;
	
	public EcType(String id,String type){
		this.setId(id);
		this.type = type;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getId() {
		return id;
	}

	public void setType(String type) {
		this.type = type;
	}

	public String getType() {
		return type;
	}

在action文件中添加list:

	private ArrayList<EcType> ecTypeList;
	public void setEcName(String ecName) {
		this.ecName = ecName;
	}
	public String getEcName() {
		return ecName;
	}
	public void setEcTypeList(ArrayList<EcType> ecTypeList) {
		this.ecTypeList = ecTypeList;
	}
	public ArrayList<EcType> getEcTypeList() {
		return ecTypeList;
	}

第三种方法一定要确定jsp,bean,action三者之间要完全对应,否则会出现下拉框有内容,但显示空白

转载于:https://www.cnblogs.com/db2zos/archive/2011/12/27/2304164.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值