<html:multibox property="kk_BlacklistVehicleRegister_DeleteCheckBox"> <bean:write name="element" property="lrdw" /> <bean:write name="element" property="czy" /> <bean:write name="element" property="lrsj" /> <bean:write name="element" property="yxq" /> <bean:write name="element" property="wfxz" /> </html:multibox>
html:multibox取多个值,再把里边的值分别取出来,我是用到了截串的方法,StringTokenizer,首先jsp已经写在了最上边,就是把值放到multibox里提交到了后台
后台:
for (int i = 0; i < kk_BlacklistVehicleRegister_DeleteCheckBox.length; i++) { kk_BlacklistVehicleRegister_DeleteCheckBox为multibox取到的值 System.out.println(kk_BlacklistVehicleRegister_DeleteCheckBox[i]); SQLErrors = true ; five = kk_BlacklistVehicleRegister_DeleteCheckBox[i]; String s = new String(five); StringTokenizer st = new StringTokenizer(s,"\t\r\n",false);//遇到的"\t\r\n"这里的东西就都不要,全部过滤 // StringTokenizer st = new StringTokenizer(s," " + "",false);//下边这种写法跟上边的完全一样,StringTokenizer 很强大吧,在你不知道制表符是什么的时候,就用这种笨蛋方法就可以,制表符就按下Tab,换行就按下回车 // 指定分隔符为"\t\r\n",将returnDelims设为false,不返回分隔符 System.out.println( "Token Total: " + st.countTokens() ); // 调用countTokens()方法返回出分隔符以外的字符的个数 while( st.hasMoreElements() ) { //返回是否还有分隔符。 System.out.println( st.nextToken() ); // 返回从当前位置到下一个分隔符的字符串。 } }
完毕
PS:kk_BlacklistVehicleRegister_DeleteCheckBox[i]的值在内存中为:
"1\r\n\t\t\t\t\t\t\t2\r\n\t\t\t\t\t\t\t2008-02-12 00:00:00.0\r\n\t\t\t\t\t\t\t2008-02-22 00:00:00.0\r\n\t\t\t\t\t\t\t3"
而 System.out.println(kk_BlacklistVehicleRegister_DeleteCheckBox[i]);显示为:
1
2
2008-02-12 00:00:00.0
2008-02-22 00:00:00.0
3
顺便说一下StringTokenizer
new StringTokenizer(s,"=",false);中的只要是双引号里边的东西,就都会被过滤掉
String s = new String("aaaaa=bbbbb!ccccc=!3ddddd232eeeee");
如new StringTokenizer(s,"=!23",false);
输出结果为
aaaaa
bbbbb
ccccc
ddddd
eeeee
new StringTokenizer(s,"=2!3",false);与new StringTokenizer(s,"=!23",false);效果完全相同,能不能过滤掉汉字,还未实验
还有一个跟这篇文章不相关的知识点,制表符,也记在这里好了
"\t\n\r ".indexOf ( c ) != -1 ;是干什么的?
---------------------------------------------------------------
是检查字符串中是否存在这个char,若没有就返回-1
黑色头发 http://heisetoufa.iteye.com
如果发现本文有误,欢迎批评指正