0

我正在使用模态 ui 组件。并且无法在 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
  };

};

小服务程序(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"));
}

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

4

1 回答 1

0

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

AngularJS POST 到服务器

于 2013-04-16T06:26:44.417 回答