0

我对java完全陌生。我有JSP登录页面。现在我想在JAVA CLASS中验证用户名和密码(硬编码)而不是servelet等。如何通过jsp做到这一点我的代码:

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;
}



}
4

1 回答 1

0
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!");
%>
}
于 2013-03-07T03:36:19.390 回答