I am absolutely new to java.I have JSP login page.Now I want to authenticate username and password(hard coded) in JAVA CLASS not servelet or etc . How to do this through jsp My code:
package FileIO;
public class Login_Authentication {
String username;
String password;
public String execute()
{
if(this.username.equals("buyer")
&& this.password.equals("buyPW"))
{
return "1";
}else
{
return "-1";
}
}
public String getUsername()
{ return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{ return password;
}
public void setPassword(String password)
{this.password = password;
}
}
you can add follow code in jsp page everywhere(import you package first)
{
<%
Login_Authentication auth = new Login_Authentication();
int result = auth.execute();
out.println(result == 1 ? "you login success" : "login fail!");
%>
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.