此代码检查登录凭据并在 getParameter(7)=1 时转发到管理员登录页面,或者当它为 0 时转发给客户 .. 如果登录凭据不正确,它将转到错误消息并从她再次登录页面..但不知何故,如果它不是管理员,它会直接进入错误页面!接下来的两个案例根本没有被检查!
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try
{
Class.forName("com.mysql.jdbc.Driver");
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/mutualfund", "root", "");
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("SELECT * FROM login_table;");
String uname= request.getParameter("username");
String pass= request.getParameter("password");
while(result.next())
{
if(result.getString(1).equals(uname) && result.getString(2).equals(pass))
{
if(result.getBoolean(7)==true)
{
response.sendRedirect("displayFunds.jsp");
}
if((result.getBoolean(7)==false) && (result.getString(4).equals("")))
{
response.sendRedirect("changePassword.jsp?name="+uname+"&&pass="+pass);
}
if((result.getBoolean(7)==false) && (!result.getString(4).equals("")))
{
response.sendRedirect("custProfile.jsp");
}
}
else
{
response.sendRedirect("loginFailed.jsp");
}
}
}
catch (Exception ex) {
Logger.getLogger(Admin.class.getName()).log(Level.SEVERE, null, ex);
}
}
}