首页 新闻 会员 周边 捐助

新手学习,求解

0
[已解决问题] 解决于 2018-05-04 09:30

不知怎么的,就出密码错误,求解!谢谢了。

<%@ page language="java" import="java.sql.*" contentType="text/html; charset=gb2312"
pageEncoding="UTF-8"%>
<!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=ISO-8859-1">
<title>登录中</title>
</head>
<body>
<%
    request.setCharacterEncoding("UTF-8");
    String driverStr = "com.microsoft.sqlserver.jdbc.SQLServerDriver";
    String connStr = "jdbc:sqlserver://localhost:1433;DatabaseName=user";
    String dbusername = "sa";
    String dbpassword = "4980";
     
    Connection conn = null;
    Statement stmt = null;
    ResultSet rs = null;    
    
    Class.forName(driverStr);
    conn = DriverManager.getConnection(connStr, dbusername, dbpassword);
    stmt = conn.createStatement();
    
    String username=(String)request.getParameter("username");
    String password=(String)request.getParameter("password");//取出login.jsp的值
    String sql="select * from login where username="+"'"+username+"'";//定义一个查询语句
    rs = stmt.executeQuery(sql);
    
    if(rs.next())
    {
        if(password.equals(rs.getObject("password"))){
            response.sendRedirect("login_success.jsp");
        }
        else{
            out.print("<script language='javaScript'> alert('密码错误');</script>");
            response.setHeader("refresh", "0;url=login.jsp");
        }
    }
    else 
    {
        out.print("<script language='javaScript'> alert('账号错误——else');</script>");
        response.setHeader("refresh", "0;url=login.jsp");
    }
    
    stmt.close();
    conn.close();
%>
</body>
</html>

丶枫的主页 丶枫 | 菜鸟二级 | 园豆:216
提问于:2017-02-22 17:50
< >
分享
最佳答案
0

if(password.equals(rs.getObject("password"))){

其中rs.getObject("password")是Object类型的,需要强转为String类型。

奖励园豆:5
徐浩进 | 菜鸟二级 |园豆:214 | 2017-03-11 13:04
其他回答(1)
0

已解决该问题

丶枫 | 园豆:216 (菜鸟二级) | 2017-04-26 19:01
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册