这句话为什么不执行?

zwliu 2004-09-10 05:00:26
if(rs.getString("us_password")!=request.getParameter("passwd"))
{
response.sendRedirect("http://localhost:8080/myjsp/errorPage.htm");
}
else
{
response.sendRedirect("http://localhost:8080/myjsp/Query.htm");
}
当两字符串相同时,并没有跳转到下一句,为什么呀?
...全文
112 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
jim3210 2004-09-11
  • 打赏
  • 举报
回复
说说 字符窜的“==”和equals的区别
“==”判断两个字符窜的引用是否相同,equals判断两个字符窜的值是否相同。
tdmlxq 2004-09-10
  • 打赏
  • 举报
回复
同意
power17 2004-09-10
  • 打赏
  • 举报
回复
注意在java中String 是对象,用==是表示两个对象在内存中是否在同一地址。你试一下下面的例子感觉一下两者的区别吧。
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>

<body>
<%
String param1="123";
String param2="123";
if(param1==param2){
out.println("true");
}
else{
out.println("false");
}
%>
<br>
<hr>
<%
String parameter1=new String("123");
String parameter2=new String("123");
if(parameter1==parameter2){
out.println("true");
}
else{
out.println("false");
}
%>

</body>
</html>
SuperKnight 2004-09-10
  • 打赏
  • 举报
回复
试试这个
--------------

if(!rs.getString("us_password").equals((String)request.getParameter("passwd")))
{
response.sendRedirect("http://localhost:8080/myjsp/errorPage.htm");
}
else
{
response.sendRedirect("http://localhost:8080/myjsp/Query.htm");
}
支持
tangbow 2004-09-10
  • 打赏
  • 举报
回复
request.getParameter (“”)得到的可能是个对象 转化成 String 试试
tangbow 2004-09-10
  • 打赏
  • 举报
回复
试试这个
--------------

if(!rs.getString("us_password").equals((String)request.getParameter("passwd")))
{
response.sendRedirect("http://localhost:8080/myjsp/errorPage.htm");
}
else
{
response.sendRedirect("http://localhost:8080/myjsp/Query.htm");
}
laughter75 2004-09-10
  • 打赏
  • 举报
回复
没错用equals();呵呵
wangwei8117 2004-09-10
  • 打赏
  • 举报
回复
应该使用字符串比较函数进行字符串的比较!如string1.equals(string2);不相等可以用 !string1.equals(string2);
lkpei 2004-09-10
  • 打赏
  • 举报
回复
字符串的比较应该用equals()方法
==是比较句柄,当然不相等。
wandou999 2004-09-10
  • 打赏
  • 举报
回复
字符串比较要用equals()
newste 2004-09-10
  • 打赏
  • 举报
回复
if(!rs.getString("us_password").equalsrequest.getParameter("passwd"))
{
response.sendRedirect("http://localhost:8080/myjsp/errorPage.htm");
}
else
{
response.sendRedirect("http://localhost:8080/myjsp/Query.htm");
}
vampirewp 2004-09-10
  • 打赏
  • 举报
回复
对于字符串的比较应该用equals()方法。
if(rs.getString("us_password").equals(request.getParameter("passwd")))
{
}

如果用“==”,只有当两个变量指向同一引用的时候才会相等
skyboy0720 2004-09-10
  • 打赏
  • 举报
回复
字符串比较要用equals()
dvictor 2004-09-10
  • 打赏
  • 举报
回复
用!equals(request.getParameter("passwd"))

81,092

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧