2017-03-29 13 views
0

jspからSpringmvcコントローラに複数のデータを送信してパスワードを変更する方法。 角度jを使用してパスワードを変更したいと考えています。 これを解決するには? いずれかお手伝いください。

警告メッセージが正しく表示されていますが、postメソッドを使用してコントローラを呼び出すことができません。

私のjsのコード

myangu.controller('account', function($scope, $http) { 

    var submitvalue = $scope.detailspassword = function() { 

     alert($scope.confirmpassword + "" + $scope.newpassword + "" 
       + $scope.existedpassword); 

    }; 
    var submitvalue = function(request) { 

    }; 
    var error = function(reason) { 
     alert("failure message: " + JSON.stringify({ 
      reason : reason 
     })); 

     $scope.errormessage = "Something Wrong.Cannot Change Your Password"; 

    }; 

    $http.post('/java/updatepassword').then(submitvalue, error); 

}); 

SpringMvcコントローラ

@RequestMapping(value = "/updatepassword", method = RequestMethod.POST,produces="application/json") 
    public @ResponseBody String updatepassword(@RequestBody Users users) throws JSONException,NullPointerException,JsonGenerationException{ 

     System.out.println("Updatedpassword"+users.getPassword()); 


     return uservice.updatepassword(users); 
    } 

JSPページ

<div class="divTablebody"> 
        <div ng-controller="account"> 
         <%-- <form:form action="/java/changepassword" method="POST" > --%> 
         <div>{{errormessage}}</div> 
         <div class="divTableRow"> 


          <div class="divTableCell">Existed password:</div> 
          <div class="divTableCell"> 
           <input type="password" placeholder="Existed Password" 
            id="Existedpw" ng-model="existedpassword"> 
          </div> 
         </div> 
         <div class="divTableRow"> 
          <div class="divTableCell">New password:</div> 
          <div class="divTableCell"> 
           <input type="password" placeholder="New Password" id="newpw" 
            ng-model="newpassword"> 
          </div> 
         </div> 
         <div class="divTableRow"> 
          <div class="divTableCell">Password Confirmation:</div> 
          <div class="divTableCell"> 
           <input type="password" placeholder="Confirm Password " 
            id="confirmpw" ng-model="confirmpassword"> 
          </div> 
         </div> 
         <div class="divTableRow"> 
          <div class="divTableCell">Save</div> 
          <div class="divTableCell"> 
           <input type="submit" id="pwsubmit" ng-click="detailspassword()" name="Submit"> 
          </div> 
         </div> 

答えて

0

あなたは2番目のパラメータとしてポストコールでデータを渡す必要があります。よりAngular#POST

EDITについては

var objPassword = { 
     existedpassword : $scope.existedpassword 
     newpassword : $scope.newpassword 
     newpassword : $scope.confirmpassword 
} 

$http.post('/java/updatepassword',objPassword).then(submitvalue, error); 

:ログインしているユーザーとパスワード

方法について 、これを試してみてくださいを変更する予定です。

myangu.controller('account', ['$scope', '$http', function ($scope, $http) { 
    $scope.detailspassword = function() { 
     alert($scope.confirmpassword + "" + $scope.newpassword + "" + $scope.existedpassword); 
     var formData = { cpass: $scope.confirmpassword, newpass: $scope.newpassword, oldpass: $scope.existedpassword }; 

     var error = function (responce) { 
      $scope.errormessage = "Unsuccessful"; 
     }; 
     $http.post('/java/updatepassword',formData).then(submitvalue, error); 
    }; 
}]); 
+0

myangu.controller( 'account'、[ \t \t '$ scope'、 \t \t '$ HTTP' \t \t関数($の範囲、$ HTTP){ \t \t \t \t \t $ scope.detailspassword =関数(){ \t \t \t \tアラート($ scope.confirmpassword + "" + $ scope.newpassword + "" \t \t \t \t \t \t + $ scope.existedpassword)。 \t \t \t \tするvar FORMDATA = { \t \t \t \t \t cpass:$ scope.confirmpassword、 \t \t \t \t \t NEWPASS:$スコープ。新パスワード、 \t \t \t \t \t oldpass:$ scope.existedpassword \t \t \t \t}; \t \t \t \t \t \t \t \t VAR誤差=関数(responce){ \t \t \t \t \t \t \t \t \t \t $ scope.errormessage = "失敗"。 \t \t \t \t \t \t \t \t \t \t}。 \t \t \t \t $ http.post( '/ java/updatepassword')。then(formData、error);}; \t \t}])。 @Ritchie –

+0

はEDITにあなたのコメントを確認してください動作していない –

+0

はい、それをチェックしますが、ブラウザ –

0

私は、このシナリオがあると思います古いパスワード、新しいパスワードとuserIdを@RequestParamsから受け取ってバックエンドを変更します(またはuserIdがない場合は何でも使用しますその後、角度

// first check if $scope.newpassword is the same value as $scope.confirmpassword 
// then send the following POST request 

$http.post('/java/updatepassword', 
    { params: { 
     "userId": userId,   // as long as, the user logged in so you can get userId somehow 
     "existedPassword": $scope.existedpassword, 
     "newPassword": $scope.newpassword 
      } 
    }) 
.then(function successCallback(response) { 
    // success 
}, function errorCallback(response) { 
    console.log(response); 
}); 

にコントローラを見て春

@RequestMapping(value = "/updatepassword", method = RequestMethod.POST,produces="application/json") 
public @ResponseBody String updatepassword(@RequestParam String userId, @RequestParam String existedPassword, @RequestParam String newPassword) { 

    // query user by userId and match if existedPassword from request param is the same as user.getPassword() 
    // if password is correct then update the password to the new password and 
    // return blabla 


} 

)あなたのDBからユーザーの情報を照会するために、電子メールのように、ユーザごとに一意であること、それはあなたが得るのを助けることを願ってこれを解決するための別の方法:)

関連する問題