0

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側でユーザーを検証する方法を知る必要があります。

4

3 に答える 3

2

@ResponseBody アノテーションを確認する

public @ResponseBody String performingLogin(@RequestParam String username, @RequestParam String password) 
{   
}
于 2012-12-27T09:49:31.313 に答える
0

また、HTTPResponseEntityを試してみることもできます。見過ごされがちですが、より細かく制御できます。Spring3.2の新しいテストパッケージで役立ちます

于 2012-12-27T10:40:00.943 に答える