0

i have angular controller which triggered with ng-click:

    app.controller('showAllWorkersContoller', function($scope, $http){
    $http.get("/SafetyManager/workers").success(function(response){
        $scope.workers = response;
        $scope.workerInfo = function(id){
            $http({
                url: '/SafetyManager/workers',
                method: "POST",
                data: { 'ID' : id },
            }).success(function(response){
                    $scope.info = response;
                });
        };
    });
});

and when i check on chrome debug it sends in form data: {'ID':"1"} (or any other id num according to the worker i click on)

but when the Servlet get the request:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    System.out.println("post request to Workers (get worker by id )");
    String id = request.getParameter("ID");
    System.out.println("this id is: " + id);


}

its print :

post request to Workers (get worker by id )

this id is: null

how can i get the ID value in the servlet?

Unknown
  • 2,037
  • 3
  • 30
  • 47
o k
  • 103
  • 1
  • 3
  • 11

2 Answers2

0

The data that you post will not be available as a request parameter, it is in the request body.

You can use a reader to read content from body.

Refer: Getting request payload from POST request in Java servlet

Community
  • 1
  • 1
Muthukannan Kanniappan
  • 2,080
  • 1
  • 16
  • 18
-1

You have to use req.getAttribute(name) to get body content.

Refer this blog: Difference between getAttribute() and getParameter()

Community
  • 1
  • 1
kumaranc
  • 105
  • 1
  • 11