0

最近、休止状態バリデーター (4.0.2.GA) を使用して、春 (3.0.5) フォームの使用を開始しました。私の検証は正常に機能し、休止状態バリデータからのエラー メッセージを表示できます。のような他のメッセージを表示する方法 :username and password mismatchおよび他のメッセージ? ここに私のフォームがあります:

   <form action="loginprocess" method="post">
       <h1>Log in</h1>
        <@spring.bind "loginForm" />
        <@spring.showErrors '*', 'errors' />
        <p>
           <label class="uname" data-icon="u"> UserName :</label>
           <@spring.formInput "loginForm.username","placeholder='eg. myusername'" />
           <@spring.showErrors "loginForm.username","error" />
        </p>
        <p>
           <label class="youpasswd" data-icon="p">Password :</label>
           <@spring.formPasswordInput "loginForm.password","placeholder='eg. @dakdjlkdja'"  />
           <@spring.showErrors "loginForm.password", "error" />
        </p>

    <input type="submit" style="background:#000; border: solid 1px #000;" value="Login"/>
        <p class="change_link">
          Not a member yet ?
        <a href="/site/authentication/signup/form" class="to_register">Sign up</a>
        </p>
  </form>

私のコントローラは次のようになります:

 @RequestMapping(value = "/site/authentication/login")
public ModelAndView nativeLogin(){
    LoginForm loginForm = new LoginForm();
   return  new ModelAndView("login","loginForm",loginForm);
}

@RequestMapping(value = "/site/authentication/loginprocess")
public ModelAndView processNativeLogin(@ModelAttribute @Valid LoginForm loginForm, BindingResult result, Model model){
    if(result.hasErrors()){

        return new ModelAndView("login","loginForm",loginForm);
    }

    try {
        Subject currentUser = SecurityUtils.getSubject();

        if (!currentUser.isAuthenticated()) {
            UsernamePasswordToken token = new UsernamePasswordToken(loginForm.getUsername(), loginForm.getPassword());
            SecurityUtils.getSubject().login(token);
        }

    } catch (UnknownAccountException uae) {
   // how to set this message to show on the form ?"Login Failed! Please check your credentials and try again.");
    } catch (IncorrectCredentialsException ice) {
   //"Login Failed! Please check your credentials and try again.");
    }
 }

誰もそれを達成する方法に光を当てることができますか? これを読んでくれてありがとう。

4

1 に答える 1

1
<#if Session.SPRING_SECURITY_LAST_EXCEPTION?? && Session.SPRING_SECURITY_LAST_EXCEPTION.message?has_content>
            <@spring.message "label.loginerror"/>: ${Session.SPRING_SECURITY_LAST_EXCEPTION.message}
</#if>

これがお役に立てば幸いです。

于 2012-08-15T10:18:54.987 に答える