【发布时间】:2018-03-08 15:19:47
【问题描述】:
如何在 HTML 文件中声明一个属性,然后在 java 类中使用它来显示错误消息?使用 .jsp 文件我知道您需要在 .jsp 文件中使用 ${example} 。 HTML文件中的正确方法是什么?我想在 "return Login.html" 之前的 else 语句中添加消息我知道 .jsp 基本上是 HTML 代码,但不知何故它在 .html 文件中使用 ${example} 不起作用。 我试过 model.put("example","something something") 但它似乎不起作用。
使用类 LoginController.java:
@Controller
public class LoginController {
@Autowired
private UserValidationService userValidationService;
@RequestMapping(value="/", method = RequestMethod.GET)
private String getLoginPage() {
return "Login.html";
}
@RequestMapping(method = RequestMethod.GET)
private String handleLoginRequests(@RequestParam String name, @RequestParam String password, ModelMap model) {
if(userValidationService.isUserValid(name,password))
return "Welcome.html";
else
return "Login.html";
}
}
HTML 文件是:
<form action="/login">
<br>
<br>
<br>
<br>
<div align="center">
<font size="6" color="white"><i><b>Welcome! Please Login</b></i></font> <br>
<br>
<br> <font color="white" size="4"><i>Enter Name</i></font> <br>
<input type="text" name="name"/> <br>
<br> <font color="white" size="4"><i>Enter Password</i></font> <br>
<input type="password" name="password"/> <br><br>
<input type="submit" name="Submit" value="Login"
style="height: 40px; width: 85px"/>
</div>
</form>
<form action="/Signup">
<div align="center" style="margin-right:auto;margin-left:auto;">
<input type="submit" name="Signup" value="Sign up" style="height:40px; width:85px"/>
</div>
<p align="center">
${example}
</p>
</form>
【问题讨论】:
标签: java html spring model-view-controller