Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript JSP
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");
          }
%>
Posted 25-Nov-12 7:27am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Replace "==" sign with .equals(Object).
 
Like if(role.equals("Customer"))
  Permalink  
Comments
Nelek at 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)



Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 25 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100