struts2中action获取checkbox中的只有空格

<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level1" value="100"/>硬座
	<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level2" value="200"/>软座/二等座(高铁)<br>
	<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level3" value="250"/>特等座/一等座(高铁)
	<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level4"  value="300"/>硬卧<br>
	<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level5" value="400"/>软卧
	<input type="checkbox" name="corpAccreditList.trainCabinLevel" id="level6" value="450"/>软包

在struts2的action中获取值的时候,

String  trainCabinLevel=“100, 200, 250”.......中间有空格

解决方法:

public String getTrainCabinLevel() {
		//struts2中action得到checkbox的值有空格,转化一下

if(trainCabinLevel!=null&&!"".equals(trainCabinLevel)){
	return trainCabinLevel.replaceAll(" ", "");
		}else{
			return trainCabinLevel;
		}
		
	}

猜你喜欢

转载自zhoushuang456oh-sina-com.iteye.com/blog/1069688
今日推荐