1

I wrote the below code to send the $http.post request

$http({
    url: '/OA_HTML/ReportColumnSelection.jsp',
    method: 'POST',
    data: JSON.stringify({myData : $scope.reportColumns}),
    headers: {'Content-Type': 'application/json;charset=utf-8'}
  })
  .success(function(response){
    $scope.viewColumns = response.columnData;
  })
  .error(function(response){
    //Error Log
    console.log('Inside saveReportColumns Error');
  });

Now the problem is i'm unable to get the "myData" JSON in ReportColumnSelection.jsp

request.getParameter("myData");

Please let me know if i'm doing anything wrong.

AngularJS Version 1.4.7

Code to save report columns:

$scope.saveReportColumns = function () { 
        console.log('Inside saveReportColumns'); 
        $http({ url: '/OA_HTML/eis/jsp/reporting/reports/newreport/columnselection/EISRSCReportColumn‌​SelectionAM.jsp', 
        method: 'POST', 
        data: JSON.stringify({myData:$scope.reportColumns}), 
        headers: {
            'Content-Type': 'application/json;charset=utf-8'
        } 
    }).success(function(response){}).error(function(response){ 
        //Error Log console.log('Inside saveReportColumns Error');
    }); 
};
3
  • Can you post some more code from your JSP where you post the request and handles the response? Commented Oct 23, 2015 at 7:32
  • Di you try data: {myData : $scope.reportColumns},? Commented Oct 23, 2015 at 7:34
  • @dfsq thanks for the suggestion. The issue got resolved when i sent the request as you suggested and in response i used request.getInputStream() Commented Oct 23, 2015 at 7:56

1 Answer 1

1

The $http services default content type is application/json, which your JSP cannot parse.

You can either,

  • change the content type of the request to application/x-www-form-urlencoded;charset=utf-8 (which might have other implications)

or

  • read it as a stream like below.

InputStream body = request.getInputStream();

It might be a good idea to leave the content type as it is, and instead read the request body and parse it with a library such as google/json

BufferedReader reader = request.getReader();
Gson gson = new Gson();
Sign up to request clarification or add additional context in comments.

2 Comments

the problem got solved with your solution. I'm able to get the JSON. Issue is i have to use Java 1.4, sadly GSON doesn't support this vesrion :(
I removed the content type and used JSON which is compatible with Java 1.4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.