我正在开发一个弹簧网络应用程序。我试着编写一个函数来检查输入的密码是否正确。 这是我的控制器的代码:
@RequestMapping(value = "/login", method = RequestMethod.POST)
public ModelAndView loginUser(@ModelAttribute User user) throws FileNotFoundException {
if (patient.getPasswort().equals(patient.getPasswortConfirm())) {
Service.login(user);
ModelAndView modelAndView = new ModelAndView("mainpage");
modelAndView.addObject("user", user);
return modelAndView;
} else {
ModelAndView modelAndView = new ModelAndView("login");
modelAndView.addObject("wrongpw", true);
return modelAndView;
}
}
这是来自html页面的代码:
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<link rel="shortcut icon" type="image/ico" href="image/favicon.ico" />
<meta charset="utf-8" />
<link rel="stylesheet" href="css/main.css" />
<script src="lib/jquery-2.1.4.js"></script>
</head>
<body>
<div id="menuebg"></div>
<p th:if="${wrongpw}"><font color="red">Password is wrong</font></p>
<div id="menue">
<form action="01erstellen" method="post" th:object="${patient}">
<table border="0px">
<tr height="20px">
<td>Name: <input th:field="*{nachname}" onchange="nameLive();" type="text" id="txtName" value="" />
</td>
</tr>
<tr height="20px">
<td>Vorname: <input th:field="*{vorname}" onchange="vornameLive();" type="text" id="txtVorname" value="" />
</td>
</tr>
<tr height="20px">
<td>Email: <input th:field="*{email}" type="text" />
</td>
</tr>
<tr height="20px">
<td><label for="gebdat"> Geburtsdatum: <input th:field="*{geburtstag}" type="date" id="gebdat" />
</label></td>
</tr>
<tr height="20px">
<td><label for="passwd">Passwort: <input th:field="*{passwort}" type="password" id="passwd" size="20" maxlength="40" />
</label></td>
</tr>
<tr height="20px">
<td><label for="passwd-confirm">Wiederholen: <input th:field="*{passwortConfirm}"
type="password" id="passwd-confirm" size="20" maxlength="40" />
</label></td>
</tr>
<tr height="20px">
<td></td>
</tr>
<tr height="20px">
<td>
<br/>
<input id="btn-send" type="submit" value="Finish" />
</td>
</tr>
<tr height="20px">
<td></td>
</tr>
</table>
</form>
</div>
</body>
</html>
我的问题是,如果我键入错误的密码,文本只会显示一瞬间,然后消失。 有人能帮我吗? 谢谢!