Spring MVCを使用していますが、サーバーを非同期で呼び出して、ユーザーの資格情報を確認する必要があります。一致する場合は、別のページにリダイレクトしています。
MyController.java
@RequestMapping("performingLogin.htm")
public ModelAndView performingLogin(@RequestParam String username, @RequestParam String password)
{
//boolean value which decides whether its a valid user
myService.performingLogin(username, password);
//Currently returning the new model to be opened irrespective of valid user
ModelAndView model = new ModelAndView("newpage");
return model;
}
MainView.jsp
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script type="text/javascript">
function doAjaxPost() {
$.ajax({
url : "dologin.htm",
data : {
username: $('#username').val(),
password: $('#password').val()
},
success : function(responseTxt,statusTxt,xhr) {
/* Opening new page */
window.location.href="newpage.htm";
}
});
}
クレデンシャルが正しくないことを警告できるように、JSP側でユーザーを検証する方法を知る必要があります。