不知道为什么一个单纯的if语句竟然不能执行,求大神帮忙看一下
<%@ page language="java" contentType="text/html; charset=UTF-8"
import="java.sql.*" import="odbc.opendb"%>
<jsp:useBean id="dbconnn" scope="page" class="odbc.opendb" />
<html>
<head>
<title>登陆</title>
</head>
<body>
<%
request.setCharacterEncoding("UTF-8");
response.setContentType("text/html;charset=utf-8");
//接收数据
String text=request.getParameter("text").trim();
String pass=request.getParameter("pass").trim();
String card=request.getParameter("card").trim();
// System.out.println(card);
// System.out.println(text);
// System.out.println(pass);
//sql语句
String sql_stu="select stu_pass from table_student where stu_ID='"+text+"'"+"and stu_pass='"+pass+"'";
String sql_tea="select tea_pass from table_teacher where tea_ID='"+text+"'"+"and stu_pass='"+pass+"'";
//System.out.println(sql_stu);
//System.out.println(sql_tea);
try{
opendb dbconn=new opendb();
dbconn.Connect();//程序只能执行到这里。。。。不知道为什么后边执行不下去
if(card=="教师")
{
//System.out.println(sql_stu);
ResultSet rs_tea=dbconn.select(sql_tea);
if(rs_tea.next())
{
out.print("<center>");
out.println("<p><font>"+"教师登陆成功</font>");
out.print("</center>");
dbconn.close();
}
}
if(card=="学生")
{
ResultSet rs_stu=dbconn.select(sql_stu);
if(rs_stu.next())
//System.out.println(rs_stu.getString("stu_pass"));
if(pass==rs_stu.getString("stu_pass"))
{
out.print("<center>");
out.println("<p><font>"+"学生登陆成功</font>");
out.print("</center>");
dbconn.close();
}
}
}
catch(Exception e){
e.printStackTrace();
}
%>
</body>
</html> jsp
[解决办法]
if(card=="教师")
你的==全都改成.equals