2017-03-24 1 views
0

"이 사용자 이름이없는 사용자"를 표시 할 수 있습니까? 컨트롤러를 통해 Spring MVC 프로젝트의 부트 스트랩 모달에 오류 메시지가 표시됩니까?Spring MVC 프로젝트의 부트 스트랩 모달에 오류 메시지 표시

내가 이름을 검증 한

@RequestMapping(value = "/recoverPassword", method = RequestMethod.POST) 
@ResponseStatus(value = HttpStatus.NO_CONTENT) 
public void sendingEmailForForgot(@RequestParam("username") String username) { 

    // Check whether email exists in DB 
    System.out.println(userDAO.getUserByName(username)); 
    System.out.println(username); 
    if (userDAO.getUserByName(username) == null) { 

     System.out.println("This ID does not exists"); 
     redirectAttributes.addAttribute("error", "wrong"); 

    } else { 
     System.out.println("mail sent to your id"); 
    } 

    // If exists then hash and send url link 
    // else error 

} 

의 login.jsp

<div class="modal-body"> 
<form id="register-form" role="form" autocomplete="off" class="form" 
    method="POST" 
    action="${pageContext.request.contextPath }/recoverPassword"> 

    <div class="form-group"> 
     <div class="input-group"> 
      <span class="input-group-addon"><i 
       class="glyphicon glyphicon-envelope color-blue"></i></span> <input 
       id="email" name="username" placeholder="your username" 
       class="form-control" type="text"> ${error} 
     </div> 
    </div> 
    <input type="hidden" name="${_csrf.parameterName}" 
     value="${_csrf.token}" /> 
    <button class="btn btn-lg btn-primary btn-block" type="submit"> 
     Send email link</button> 

</form> 

컨트롤러 여부 존재하는 경우,하지만 어떻게 같은 현재 열려있는 모달에 해당 오류를 표시합니다 ?

컨트롤러를 통해 가능하지 않은 경우 다른 방법으로 공유하십시오.

+0

난 당신이 현재 열려있는 모달 당신은 안녕 당신이 좀 더 빛을 던질 수 AJAX – Plog

+0

을 통해 그것을 할 필요를 변경하고자한다면 생각? –

+0

웹 서비스에서 응답을 얻지 않고 어떻게 부트 스트랩 모달에서 무엇을 표시 할 수 있습니까? 그리고 스프링의 어떤 버전을 사용하고 있는지가 매우 중요합니다. –

답변

0

마지막으로 AJAX를 통해 해결했지만 여전히 컨트롤러를 통해 가능한지 알 수 없습니다. 나를 위해 잘 작동 내가 사용했던이 :

function doAjaxPost() { 
    // get the form values 
    var name = $('#name').val(); 
    var education = $('#education').val(); 

    $.ajax({ 
     type: "POST", 
     url: contexPath + "/AddUser.htm", 
     data: "name=" + name + "&education=" + education, 
     success: function(response){ 
      // we have the response 
      if(response.status == "SUCCESS"){ 
       userInfo = "<ol>"; 
       for(i =0 ; i < response.result.length ; i++){ 
        userInfo += "<br><li><b>Name</b> : " + response.result[i].name + 
        ";<b> Education</b> : " + response.result[i].education; 
       } 
       userInfo += "</ol>"; 
       $('#info').html("User has been added to the list successfully. " + userInfo); 
       $('#name').val(''); 
       $('#education').val(''); 
       $('#error').hide('slow'); 
       $('#info').show('slow'); 
      }else{ 
       errorInfo = ""; 
       for(i =0 ; i < response.result.length ; i++){ 
        errorInfo += "<br>" + (i + 1) +". " + response.result[i].code; 
       } 
       $('#error').html("Please correct following errors: " + errorInfo); 
       $('#info').hide('slow'); 
       $('#error').show('slow'); 
      } 
     }, 
     error: function(e){ 
      alert('Error: ' + e); 
     } 
    }); 
} 
관련 문제