Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8640781
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T11:21:49+00:00 2026-06-12T11:21:49+00:00

I want to send my JSON object from Javscript to Struts2 Action. Sample JSON

  • 0

I want to send my JSON object from Javscript to Struts2 Action.

Sample JSON Object

  {
        "lists":["list1","list2","list3","list4","list5"],
        "maps": {  
            "key4":"value4","key3":"value3","key5":"value5","key2":"value2","key1":"value1"
        },
        "number1":123456789,
        "numberarray1":[1,2,3,4,5,6,7,8,9],
        "string1":"A",
        "stringarray1":["A1","B1"]
    }

My Jquery Ajax

$.ajax({
    type: 'POST', 
    url: 'json/JSON.action',
    data: JSON.stringify(data),
    dataType: 'json',
    async: false ,
    contentType: 'application/json; charset=utf-8',
    success: function(){window.alert('Done');}
});

Struts.xml config

<action name="JSON" class="com.actions.json.JsonAction" method="getJSON">
    <result type="json"/>
</action>   

My Action Class

public class JsonAction extends ActionSupport {


    private String data;


    public String getJSON() {


        return ActionSupport.SUCCESS;
    }

    public String getData() {
        return data;
    }

    public void setData(String data) {
        this.data = data;
    }



}

My Problem is how to receive the JSON Object in Action Class.

NOTE: POST OF JSON object is successful.. I just don’t know how to receive it via Action Class.. PLEASE HELP
Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T11:21:50+00:00Added an answer on June 12, 2026 at 11:21 am
    1. There is a typo in your struts.xml entry
    2. Have you defined tiles result and interceptor in struts.xml . Please see this link
    3. The json you are sending to the server, doesn’t contain any data key. So it will be always null.
      Since json is denoted as objects. You need to convert JSON into Java objects in this way.

    Approach 1.

    Create setters for lists,maps,number1,numberarray1,string1 and so on. In the top of this link, is defined the way to do it. Then you can access all the variables in this way.

    Approach 2.
    In your javascript define a new object.

     var sentData ={};
     sentData ["sentData "] = data;
    // And in your ajax call , 
    data: JSON.stringify(sentData),
    

    And in your action class, create getters and setters for this.

    Map<K.V> sentData = new HashMap<K,V>();
    

    This will give you whole json object as a Map.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to send a JSON object from the client to an action on
I want to return a json object from the onreadystatechange = function(){}, but I
I want to send a json from c# application to the client. I want
I want to send a JSON object to facebook, but only using javascript/ajax i.e
i want to send a json string from a html webpage using javascript to
So i send an Json object to my server, and i want to convert
I want to receive json object from view to controller using $.ajax method but
Want to send the text from my current vb application to the Active Window
I want to convert the html tag objects to json object in the javascript
I want to send the following JSON text {Email:aaa@tbbb.com,Password:123456} to a web service and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.