이 jsp 코드를 작성했습니다. 기본 로그인 컨트롤입니다. 내 데이터베이스로 입력을 확인하려고합니다. 그들이 올바른지 아무 문제가 있지만 입력이 null이거나 데이터베이스에없는 경우 오류를 제공하고 게스트를 로그인 페이지로 리디렉션하려고합니다. 이 코드 두 줄에 JSP의 out.println
<%@ page import ="java.sql.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Process</title>
</head>
<body>
<%
String userid = request.getParameter("username");
String pwd = request.getParameter("password");
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost/ecommerce", "root1" , "1234");
Statement st = con.createStatement();
ResultSet rs;
rs = st.executeQuery("select * from users where UserFirstName='" + userid + "' and UserPassword='" + pwd + "'");
while(rs.next()){
if(userid.length()!= 0 || pwd.length()!= 0){
if (rs.getInt("Admin") == 1) {
session.setAttribute("userid", userid);
response.sendRedirect("Admin.jsp");
} else if(rs.getInt("Admin") == 0){
session.setAttribute("userid", userid);
response.sendRedirect("User.jsp");
}
else {
out.println("Invalid username or password <a href='index.jsp'>try again</a>");
}
}
else{
out.println("Empty username or password <a href='index.jsp'>try again</a>");
}
}
%>
</body>
는
else {
out.println("Invalid username or password <a href='index.jsp'>try again</a>");
}
작동하지 않습니다이 하나
else{
out.println("Empty username or password <a href='index.jsp'>try again</a>");
}
브라우저는 대신 나에게 다른 범위를 빈 페이지를 제공합니다.
테스트 사례를 공유하십시오. 문제를 재현하는 단계는 무엇입니까? – Braj
손님이 비어있는 사용자 이름 또는 비밀번호를 인쇄해야하는 것보다 빈 줄을 제출하는 경우 잘못된 사용자 이름 또는 비밀번호를 입력하면 잘못된 사용자 이름 또는 비밀번호가 인쇄됩니다. 그게 전부 – TheHost
단순히 데이터베이스 쿼리를 실행하기 전에'null'과 빈 문자열을 확인하십시오 – Braj