not able to get value fo textarea in servlet using angularjs

751 Views Asked by At

I'm using modal ui-component. and not able to get value of textarea in servlet, below are the code: index.html:

<div modal="shouldBeOpen" close="close()" options="opts">
<div class="modal-header">
<h4>Text Editor</h4>
</div>
<div class="modal-body">
<div class="boxes">
<textarea ui:tinymce name="textBody" ng:model="textBody"></textarea>
</div>
</div>
<div class="modal-footer">
<button class="btn btn-success submit" ng-click="submit()" >Submit</button>
<button class="btn btn-warning cancel" ng-click="close()">Cancel</button>
</div>

Controller:

var ModalDemoCtrl = function ($scope,$http,$location) {

  $scope.open = function () {
    $scope.shouldBeOpen = true;
  };

  $scope.close = function () {
    $scope.closeMsg = 'I was closed at: ' + new Date();
    $scope.shouldBeOpen = false;
  };

  $scope.submit = function () {
          $http.post("/FormSubmitServlet",$scope.textBody).
             success(function(data) {
                     });
          $scope.shouldBeOpen = false;
          };

  $scope.opts = {
    backdropFade: true,
    dialogFade:true
  };

};

Servlet(FormSubmitServlet):

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                String textAreaValue = request.getParameter("textBody");
                System.out.println(textAreaValue);
                System.out.println(request.getAttribute("textBody"));
}

Kindly check what is wrong with this code. Thanks in advance.

1

There are 1 best solutions below

1
On

The problem is how Angular is sending the data to the server... Open your developer tools in your browser and look at the XHR request.. the data is being sent in the request body as a JSON object - not standard form data. I'm not familiar with Servlets, but I found this question that should help you a lot:

AngularJS POST to Server