当前位置: 技术问答>java相关
n简单的问题,怎么不相等哪?(jsp)
来源: 互联网 发布时间:2015-04-12
本文导语: url是http://localhost:8080/my/info/sysadmin/post.jsp?action=login 代码 String action=request.getParameter("action"); //登录处理过程 out.println(action); out.println(action.length()); out.println((action=="login")); 结果 login 5 false 怎么会是false? ...
url是http://localhost:8080/my/info/sysadmin/post.jsp?action=login
代码
String action=request.getParameter("action");
//登录处理过程
out.println(action);
out.println(action.length());
out.println((action=="login"));
结果
login 5 false
怎么会是false?
代码
String action=request.getParameter("action");
//登录处理过程
out.println(action);
out.println(action.length());
out.println((action=="login"));
结果
login 5 false
怎么会是false?
|
action.equals("login")
这个大小写敏感
如果忽略大小写
action.equalsIgnoreCase("login")
action 和 "aciton"是两个不同的类
所以不等。
这个大小写敏感
如果忽略大小写
action.equalsIgnoreCase("login")
action 和 "aciton"是两个不同的类
所以不等。
|
呵呵,String 是 Object ,所以比较要用 equals
int比较相等就可以用 ==
但是 Integer 就需要用equals,因为Integer是 Object
int比较相等就可以用 ==
但是 Integer 就需要用equals,因为Integer是 Object
|
用equals是比较值,就会得到你想要的结果了。
|
((action=="login"));
逻辑表达式,只有 TRUE 和FALSE
逻辑表达式,只有 TRUE 和FALSE
|
action=="login"
action is a reference to a block of memory. You may think that it is an address like ( 0x0AB.... ). "login" is another block of memory with address different from (0x0AB...), eg.(0x0BB...). == just compare the two addresses. The result is false.
To check if action is "login", use action.equals("login"). don't use == to compare Objects.
action is a reference to a block of memory. You may think that it is an address like ( 0x0AB.... ). "login" is another block of memory with address different from (0x0AB...), eg.(0x0BB...). == just compare the two addresses. The result is false.
To check if action is "login", use action.equals("login"). don't use == to compare Objects.
|
equals 和 equalsIgornCase 是比较字符串的.
==
==