Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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


--%>
JavaScript
<%@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");
          }
%>
Posted

1 solution

Replace "==" sign with .equals(Object).

Like if(role.equals("Customer"))
 
Share this answer
 
Comments
Nelek 25-Nov-12 14:20pm    
OP's comment moved from non-solution below
coolloud13 thnx for the reply, i did as you sugested but there is no change in to the output. is is still the same

OP's comment moved from non-solution below (2)
FINALLY IT IS WORKING. I REARRANGED THE IF STATEMENT. THANK YOU coolloud13

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900