У меня есть такой код:
LoginServlet
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("txtusername");
String password = request.getParameter("txtpassword");
if(username.equals("gogikole") && password.equals("1234"))
{
response.sendRedirect("mainMenu.jsp");
}
//else
// {
// System.out.println("error");
// }
}
}
login.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Login</title>
</head>
<body>
<form method="post" action="LoginServlet"></form>
<table>
<tr>
<td>User name</td>
<td><input type="text" name="txtusername"></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="txtpassword"></td>
</tr>
<tr>
<td></td>
<td><input type="submit" value="login"></td>
</tr>
</table>
</body>
</html>
Я смотрел на Youtube это: учебник
и там все отлично работает. Я сделал все, как там, но когда я нажимаю кнопку «Войти», он не перенаправляет меня на mainMenu.jsp
На данный момент mainMenu.jsp просто приветствует вас.
Как перейти в главное меню, если имя пользователя и пароль совпадают, после нажатия кнопки «Отправить»?