关于JSP中request.getParameter()判断得到否为空的问题

代码中的像这样的语句:
String name=Bytes(request.getParameter("name"));//Bytes()为格式化表单参数的乱码
if(name!= null && name.trim().length>0)
{}
运行后出现这个错误:
org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 69 in the jsp file: /company/index1_3_1.jsp
length cannot be resolved or is not a field
66: if(Bean.connection())
67: {
68: String sql="update conference_room set ";
69: if(name!= null && name.trim().length>0)
70: {sql=sql+"name='"+name+"'";
71: if(address!=null && address.trim().length>0)
72: sql=sql+",address='"+address+"'";
求解:如何判断request得到的数据为空?

String name=Bytes(request.getParameter("name"));//Bytes()为格式化表单参数的乱码
f(name!= null && "".equals(name.trim()))
{}
这样写绝对没有问题,应该这样写是最标准的写法,先判断是否为空,如果不为空,再于空字符串比较

注意:空字符串并不代表为空
温馨提示:答案为网友推荐,仅供参考
第1个回答  2009-08-28
length改成length()本回答被提问者采纳
第2个回答  2009-08-28
if(name!= null && name.trim()="")
ok试一下
第3个回答  2009-08-28
编码是否标准且不说,应该是一楼说的获取字符串长度的leng方法没有加()的问题 修改一下试试

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网