String prename = request.getParameter("name")==null?"":request.getParameter("name").trim();
String description = request.getParameter("description")==null?"":request.getParameter("description").trim();
String baseprice = (request.getParameter("baseprice")==null||
String description = request.getParameter("description")==null?"":request.getParameter("description").trim();
String baseprice = (request.getParameter("baseprice")==null||
request.getParameter("baseprice" )=="")?"0":request.getParameter("baseprice").trim();
System.out.println("prename:"+(request.getParameter("name")==null)+
", description:"+(request.getParameter("description")==null)+
", baseprice:"+(request.getParameter("baseprice")==null||request.getParameter("baseprice")==""));
System.out.println((request.getParameter("baseprice")==null)+"----");
System.out.println((request.getParameter("baseprice")=="")+"JJJJJ");
double a =Double.parseDouble("0");
System.out.println(a);
System.out.println("prename:"+(request.getParameter("name")==null)+
", description:"+(request.getParameter("description")==null)+
", baseprice:"+(request.getParameter("baseprice")==null||request.getParameter("baseprice")==""));
System.out.println((request.getParameter("baseprice")==null)+"----");
System.out.println((request.getParameter("baseprice")=="")+"JJJJJ");
double a =Double.parseDouble("0");
System.out.println(a);
----------------------------------------------------------
运行结果:
prename:false, description:false, baseprice:true
false----
trueJJJJJ
0.0
false----
trueJJJJJ
0.0
-----------------------------
分析:1.request.getParameter("baseprice")==null 输出为false
request.getParameter("baseprice")=="" 输出为true
说明baseprice不输值时request.getParameter("baseprice")取出的为空串。
2.System.out.println((request.getParameter("baseprice")=="")+"JJJJJ");
如果加号前没有括号
System.out.println(request.getParameter("baseprice")==""+"JJJJJ");
输出为false
输出为false
因为+号先于==执行。