无法使用angularjs获取servlet中textarea的值

时间:2013-04-16 05:24:54

标签: richtextarea

我使用模态ui-component。并且无法在servlet中获取textarea的值,下面是代码: 的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>

控制器:

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"));
}

请检查此代码有什么问题。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

问题是Angular如何将数据发送到服务器...在浏览器中打开您的开发人员工具并查看XHR请求..数据作为JSON对象在请求正文中发送 - 而不是标准表单数据。我不熟悉Servlets,但我发现这个问题对你有很大帮助:

AngularJS POST to Server