java 中 jsp页面怎么过滤文本框中的 头尾空格 有几种方法!!!

比如这个

第1个回答  2014-01-23
在你得到的数据的后面加上 .trim()就可以了
例:
String ss=request.getParameter("strname").trim();
<input type="text" name="strname">

这样可以了.本回答被提问者采纳
第2个回答  2014-01-23
试试这个,js字符串直接调用trim()方法
String.prototype.trim = function(){
return this.replace(/(^\s*)|(\s*$)/g, "");
};
第3个回答  2014-01-23
可以用trim()来去掉首尾空格
第4个回答  2018-03-28
可以用字符串方法,切割,将空格切割掉.
str.split(" ");
或者首位去空格
str.trim();
或者用替换
nstr.replaceAll(" ","" );
相似回答