帮助修复登录逻辑错误 [英] HELP TO FIX LOGIN LOGICAL ERROR

查看:96
本文介绍了帮助修复登录逻辑错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在为一个网站开发一个登录页面,该页面具有3个不同的首页1用于客户,2用于员工3用于管理员,该代码应根据以下内容确定要重定向到正确主页的网页:在角色变量上.我面临逻辑错误,代码总是以打开home3页面结尾.这是我的代码


-%>

i am currently developing a login page for a web site which has 3 different homepages 1 for customers, 2 for employees 3 for the administrator, the code is supposed to decide the webpage that it is supposed to redirect to the correct homepage based on the role variable. i am facing a logical error, the code always ends up opening the home3 page. here is my code


--%>

<%@page import="java.sql.*"%>

<%
int id;
String role=request.getParameter("role");
if(role =="Customer")
          {
                     id=3;
          }
         else if(role=="Employee")
          {
                       
                     id=2;
          }
else
       {
                     id=1;
                       
}
String user=request.getParameter("user");
String pass=request.getParameter("pass");
 Class.forName("com.mysql.jdbc.Driver").newInstance();
    Connection con=DriverManager.getConnection("jdbc:mysql://localhost:3306/flymywaysystem","root","12345");  
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from registeredcustomer where username='"+user+"' and password='"+pass+"'");
int count=0;
          while(rs.next())
          {

                   count++;
          }

                    if(count>0)
          {
            switch (id) {
            case 1:  response.sendRedirect("home.jsp"); break;
            case 2:  response.sendRedirect("home2.jsp"); break;
            case 3: response.sendRedirect("home3.jsp");break;
        }
          }
          else
          {
                       
                      response.sendRedirect("login.jsp");
          }
%>

推荐答案

替换 " ==" .equals(Object)签名.

if(role.equals("Customer"))
Replace "==" sign with .equals(Object).

Like if(role.equals("Customer"))


这篇关于帮助修复登录逻辑错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆