Cadeq Cadeq - 3 months ago 10x
Java Question

AngularJs send value to Struts2

i am having some problems to receive a value from angularJS in struts2 action.

The objective is to receive the index of the current image in a carousel.


var app = angular.module('menuAPP', ['ui.bootstrap']);
app.controller('mainController', function($scope, $http, $window, $location) {
$ = function() {

$scope.currentIndex = $('').index() + 1;//Carousel index
var params = "NSlider :"+ $scope.currentIndex;
var data = angular.toJson(params)
method: 'post',
url: 'showArm',
data: 'NSlider =' + data

import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.opensymphony.xwork2.Action;

public class BrazoAction implements Action
private static final Logger log = LogManager.getLogger(BrazoAction.class);
private String NSlider;

public String execute() throws Exception {

HttpSession session = ServletActionContext.getRequest().getSession();

String aux = NSlider.split(":")[1]; //Receive "NSlider : {int}"
session.setAttribute("id_brazo", aux);
return SUCCESS;

public String getNSlider() {
return NSlider;

public void setNSlider(String NSlider) {
this.nSlider = NSlider;


This jsp must show the index of selected picture in the carousel.


<script src="lib/threejs/three.min.js"></script>
<script src="lib/threejs/OrbitControls.js"></script>
<script src="lib/threejs/dat.gui.min.js"></script>
<script src="lib/threejs/stats.min.js"></script>
<script src="js/webGL.js"></script>
<div id='container' width=800, height=600>

If I debug the action, I can see that i don't receive any value from angular.

Changed the json petition, changed the name of get and set and also changed to string the parameter.

Now i receive null value. Still not working well.

Now show the final result. Now works fine.


This is how i pass data to Struts action please take reference from this.

$scope.submitForm = function() {

        var params = {
            "name" : $,
            "username" : $scope.username,
            "email" : $

        var data = angular.toJson(params);
        $http( {
            method : 'POST',
            url : '/angular/studentForm.action',
            data : 'value=' + data,
            headers : {
                'Content-Type' : 'application/x-www-form-urlencoded'
        }).success(function(data) {
            if (data.errors) {
                $scope.errorname =;
                $scope.errorUsername = data.errors.username;
                $scope.erroremail =;
            } else {
                $scope.message = data;

        }).error(function(data, status) {
            return false;

You have to change the parameter to string because angular js only works with json data.