Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

168
Views
How to get raw JSON data using Struts2 Ajax call

I am getting [object Object] response in console while I expect a full JSON.

As per my action class :

public String getDensityData(){
    SessionFactory sf = (SessionFactory) ctx.getAttribute("SessionFactory");
    ProductDAO product = new ProductDAOImpl(sf);
    List<DensityGroup> densityList = product.getDensity();
      Gson gson = new Gson();
      densityjson = gson.toJson(densityList);
      System.out.println("JSON: "+densityjson);
    return "success";
}

Struts.xml

<package name="json" namespace="/" extends="json-default">
    <action name="getJSON" class="com.bmm.action.ProductAction" method="getDensityData">
        <param name="noCache">true</param>
        <param name="excludeNullProperties">true</param>
        <param name="root">densityjson</param>
        <result name="success" type="json">/product_master.jsp</result>
</action>  
</package>

JSP:

$.ajax({
    type: "POST",
    url: '<s:url namespace="/" action="getJSON"/>',
    data: "json",
    success: function(data){
    console.log(""+data);
    }
});
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

If you expect to get JSON from the response, you should specify a dataType property. JSON is a javascript Object, if you need to print it use JSON.stringify().

$.ajax({
    type: "GET",
    url: '<s:url namespace="/" action="getJSON"/>',
    dataType: "json",
    success: function(data){
        console.log(JSON.stringify(data));
    }
});
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!