I have two files, one is the front-end login.jsp
and the back-end loginUser.java
. I am trying to get the boolean
from the loginUser.java
. However, there come out a error java.lang.IncompatibleClassChangeError
. I have no idea why this come out. How can I solve this error? Thanks.
Here is my code of 'login.jsp':
try{
out.println("HT");
login.LoginUser user = new login.LoginUser(id,pwd);
boolean login_success = user.isLogin(); <---This line have error.
//int role_id = user.get_role_id();
if (login_success){
out.println("Login Success");
// out.println(user.get_role_id().toString());
%>
<script>
setTimeout(function () {
window.location.href = "control_panel.jsp"; //will redirect to your blog page (an ex: blog.html)
},2000);
</script>
<%
}
else{
out.println("Login Failed");
%>
Here is my code of 'loginUser.java':
public class LoginUser {
private String username,password;
public boolean login_success;
public int role_id;
public LoginUser(String username,String password){
this.username=username;
this.password=password;
this.login_success=false;
this.role_id = 0;
}
public boolean login(){
db.DataConnect conn = new db.DataConnect();
conn.connect();
ResultSet login_result;
String sql_statement = "SELECT COUNT(*) AS user_found, role_id FROM t_user WHERE user_name = '" + this.username + "' AND password = '" + this.password + "'";
System.out.println(sql_statement);
try{
login_result = conn.select(sql_statement);
if(login_result.next()){
if(login_result.getInt("user_found") == 1){
login_success = true;
role_id = login_result.getInt("role_id");
}
}
} catch (Exception e) {System.out.println(e);}
conn.close();
return login_success;
}
public boolean isLogin(){
return true;
}
}
However, the when I changed the line boolean login_success = user.isLogin();
to boolean login_success = user.login();
, the error will not come out.