Satyadev Satyadev - 1 year ago 76
AngularJS Question

Sending text area values as request to spring is always null

I have two textarea boxes like this:

<div class="form-group">
<label for="comment">Numbers:</label>
<textarea class="form-control" rows="3" ng-model="numbers" placeholder="Numbers in one per line format"></textarea>
<label for="comment">Message:</label>
<textarea class="form-control" rows="2" ng-model="message" ng-trim="true" placeholder="Enter your message here"></textarea>

I am sending the request from angular:

$scope.sendSMS = function () {
var formData = {
numbers: $scope.numbers,
message: $scope.message

Auth.sendSMS(formData, successAuth, function () {
console.log(JSON.stringify(formData)); //prints both values
$rootScope.error = 'Message not sent';

Auth service (http post):

sendSMS: function(data, success, error){
$'mvc-dispatcher/sendSMS', data).success(success).error(error);

While on front-end I am able to print both the values before sending, however on server-side the text area for message is always taking it is null and text-area for number is printing correctly:

Numbers: 123456789
message: null

I am not sure what went wrong. There is no error on server-side nor frontend

Rest Controller:

public class smsController {

@RequestMapping(value = "/sendSMS", consumes = "application/json", headers = "content-type=application/x-www-form-urlencoded")
public void sendMessage(@RequestBody MessageBean msgBean) {

String numbers = msgBean.getNumbers();
System.out.println("Numbers: " + numbers);
String message = msgBean.getMessages();
System.out.println("message: " + message);


<beans xmlns=""
xmlns:mvc="" xmlns:xsi=""

<context:component-scan base-package="" />
<mvc:annotation-driven />

<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/views/"/>
<property name="suffix" value=".jsp"/>

Jars used:

Spring Framework release 4.2.2

Message Bean:

public class MessageBean {

private String numbers;
private String messages;

public String getNumbers() {
return numbers;

public void setNumbers(String numbers) {
this.numbers = numbers;

public String getMessages() {
return messages;

public void setMessages(String messages) {
this.messages = messages;

Answer Source

You've got a wrong parameter name, try this;)

var formData = {
    numbers: $scope.numbers,
    message: $scope.message

Now we are clear, you declared a field messages in MessageBean, but you tried to give it a parameter named message, message will not be matched to messages when Spring do convertering things, so you should try this;)

var formData = {
    numbers: $scope.numbers,
    messages: $scope.message