求教!jsp+mysql,if (check=="t")判断语句无法正确判断字符
我想实现通过判断check的值,check=t则输出“审核通过”,check=f输出“未审核”,可是所有判断输出都是“未审核”。于是,我对check进行输出,发现输出的值都是正确的,效果如下:
我的源代码如下(初学,代码不规范,见谅!):
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*"
errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<script type="text/JavaScript">
<!--
function MM_callJS(jsStr) { //v2.0
return eval(jsStr)
}
//-->
</script>
<%
Class.forName("com.mysql.jdbc.Driver");
String url= "jdbc:mysql://localhost:3306/graduationproject?user=root&password=123";
Connection connection=DriverManager.getConnection(url);
Statement statement = connection.createStatement();
String sql="select * from supplier";
ResultSet rs = statement.executeQuery(sql);
%>
</head>
<body>
<table width="735">
<tr>
<th width="74" scope="col">ICP</th>
<th width="197" scope="col">供应商名称</th>
<th width="131" scope="col">原料</th>
<th width="135" scope="col">报价</th>
<th width="174" scope="col">性质</th>
</tr>
</table>
<%
while(rs.next()) {
String ICP = rs.getString ( "ICP" );
String name = rs.getString ( "name" );
String material = rs.getString ( "material" );
String price = rs.getString ( "price" );
String check = rs.getString( "check" );
%>
<table width="735">
<tr>
<th width="71" scope="col"><a href="supplier_detail.jsp?ICP=<%=ICP %>"><%=ICP %></a> </th>
<th width="199" scope="col"><%=name%> </th>
<th width="132" scope="col"><%=material%> </th>
<th width="134" scope="col"><%=price%> </th>
<th width="175" scope="col"><%=check %><% if (check=="t") {out.print("审核通过");}
else {out.print("未审核");}%>
</th>
</tr>
</table>
<p>
<% } %>
</p>
<p><a href="manu.jsp">返回</a></p>
</body>
</html>
------解决方案--------------------字符串不是用 ==的 。。int的才是。。比如说 a==1
字符串用的是 a.equals("t");
------解决方案--------------------用这个试下
Java code
if(check.trim().equals("t")){
//do something
}else if(check.trim().equals("f")){
//do another
}
------解决方案--------------------
"t".equals(check)
------解决方案--------------------
哈哈,你走运了!!!
这个问题也我也碰到了,
解决办法如下:
先判断下chec