求助:MYSQL与JSP做的用户登录与注册问题
来源:百度知道 编辑:UC知道 时间:2024/05/28 20:23:53
我用MYSQL与JSP做了一个用户登录与注册,现在遇到问题向各位求助,注册后的只有在数据库中排第一的能登录,但是把第一个删了,第二个也能登录,主是什么问题呢?
代码如下:check_login.jsp
<%@ include file="db.jsp" %>
<%@ page session="true" buffer="16kb" import="java.util.*,java.text.*"%>
<%@ page contentType="text/html; charset=gb2312" %>
<%
if (rs.next()) {
// Setup variables
String username = request.getParameter("username");
String passwd = request.getParameter("passwd");
if ((username.equals(rs.getString("username"))) && (passwd.equals(rs.getString("passwd")))) {
// Write cookies
response.sendRedirect("./myroom/inf.jsp");
}else{
response.sendRedirect("login_error.jsp");
}
}
%>
db.jsp
<%@ page import="java.sql.*"%>
<%
try{
Class.forName("com.mysql.jd
代码如下:check_login.jsp
<%@ include file="db.jsp" %>
<%@ page session="true" buffer="16kb" import="java.util.*,java.text.*"%>
<%@ page contentType="text/html; charset=gb2312" %>
<%
if (rs.next()) {
// Setup variables
String username = request.getParameter("username");
String passwd = request.getParameter("passwd");
if ((username.equals(rs.getString("username"))) && (passwd.equals(rs.getString("passwd")))) {
// Write cookies
response.sendRedirect("./myroom/inf.jsp");
}else{
response.sendRedirect("login_error.jsp");
}
}
%>
db.jsp
<%@ page import="java.sql.*"%>
<%
try{
Class.forName("com.mysql.jd
最后三条代码,应该是:
Statement stmt = conn.createStatement();
String sql = "select * from userinfo where username='"+username+"' and password='"+password+"'";
ResultSet rs = stmt.executeQuery(sql);
当然,要在你的类里边加入构造来定义这两个变量