<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;
}
}
本文介绍了一个在Struts2框架中处理从表单接收的Checkbox值时遇到的问题及解决方案。当Checkbox的值中包含空格时,会导致数据解析错误。文章提供了一种简单的方法来移除这些空格,确保数据的正确处理。
382

被折叠的 条评论
为什么被折叠?



