i work on a little project and i need to do a 'login' rediriction but without database just a test on a username/password strings.
I did a index.jsp file where i have a form with input text field for login and same for the password.The method is post:
<form name="form" method="post" action="http://localhost:8080/Miniproject/Authservlet">
<label for="login">Login</label><br>
<input type="text" name="login" id="login">
<br>
<label for="password">Password</label><br>
<input type="password" name="password" id="password">
<br><br>
<input type="submit" value="Me connecter" id="button_submit">
</form>
then i have a servlet with a dopost method defined like this:
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
String login = request.getParameter("login");
String password = request.getParameter("password");
boolean result = Authentication.checklogin(login,password);
request.setAttribute("result",result);
request.setAttribute("login",login);
request.setAttribute("password",password);
if (result) {
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/view/welcome.jsp");
dispatcher.include(request, response);
} else {
RequestDispatcher dispatcher=getServletContext().getRequestDispatcher("/view/error.jsp");
dispatcher.include(request, response);
}
doGet(request, response);
}
I have a Authentication class defined like this (I removed setters and getters for my post but they exist in ther class) :
public class Authentication {
public String login;
public String password;
public static boolean checklogin( String login ,String password ) {
if (login == "username" && password=="password") {
return true;
} else {
return false;
}
}
}
the form is submitted, the login/password string that i get from "request parameters" are ok, the method is static and i return true or false but when i do this i always have a result = null in the servlet but i should get a result = true or false... i don't understand why
i tried to do it with int, string but i have no return.the Authentication class is imported in the servlet like this:
import package.model.Authentication;
if someone can explain me why the method is not working it would be perfect, thanks :D