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

  • SEARCH
  • Home
  • 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 8556947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:27:52+00:00 2026-06-11T15:27:52+00:00

I am working on a spring mvc web application, in which I am using

  • 0

I am working on a spring mvc web application, in which I am using Google Visualization API for generating some charts. I have a model class which contains 2 arraylists, which represent the data that I`m sending to the function that draws the chart (this is what i want to be converted to a JSON).

The model class:

@Component
public class JsonResponse {

private List<Integer> percentages = new ArrayList<Integer>();
private List<String> topics = new ArrayList<String>();

public JsonResponse(){
}

public List<Integer> getPercentages() {
    return percentages;
}

public void setPercentages(List<Integer> percentages) {
    this.percentages = percentages;
}

public List<String> getTopics() {
    return topics;
}

public void setTopics(List<String> topics) {
    this.topics = topics;
}
}

Then Ive got a@Component` annotated class which contains a method that returns a model object (of the class that I wrote above), with the 2 arraylists attributes populated.

@Component
public class ChartUtils {
    @Autowired
    public JsonResponse response;

    public JsonResponse listPieChartData( ModelAndView model ,int waveId ){

    //arraylists for chart generation
List<Integer> percentages = new ArrayList<Integer>();
List<String> topics = new ArrayList<String>();

    {... code for accessing the DB and processing some data and then populating the 2                  
     arraylists ... }

response.setTopics(topics);
response.setPercentages(percentages);

return response;}
}

So the Controller class, the one that has the mapping for the action that I am calling to gather data for the chart generation and in which I am calling listPieChartData method, from the class above, and in which I’m also using the @ResponseBody annotation is this:

@Controller
public class ChartController {

@Autowired
public ChartUtils utils;

@Autowired
public JsonResponse response;

@RequestMapping(value = "/drawPieChart", method = RequestMethod.GET )
@ResponseBody
public JsonResponse drawPieChart( ModelAndView model,
        @RequestParam(value = "id", defaultValue = "-1") int waveId ) {

    return utils.listPieChartData(model,waveId ); }

The JavaScript function that draws the chart :

function drawColumnChart(percentages, topics , div,width,height) {
    var data = new google.visualization.DataTable();

data.addColumn('string', 'Wave');
for (var i=0; i < topics.length; i++){
    data.addColumn( 'number', topics[i] ); 
}

    data.addRow( percentages );

    var wave=percentages[0];
    var options = {
        'title':'Generated Chart For '+wave,
        'backgroundColor': { fill: "none" },
        'is3D': true,
        'width':width,
        'height':height,
    };

var chart = new google.visualization.ColumnChart(document.getElementById(div));
chart.draw(data, options);

}

And the AJAX call to the controller’s mapped method (for gathering data) that finally calls the above JS function to obtain the chart (I’m also sending the request param int id for the controller method , I didn’t wrote that)

$("#button").live("click", function(){

var arrayP, arrayT;
$.ajax({
    url: "drawPieChart",      
contentType: "application/json",
data: params,
success: function(data) {
    $.each(data, function(messageIndex, message) {
    if (messageIndex === 0) {
            arrayP = message;
    } else {
    arrayT = message;
    }
        });
    drawPieChart(arrayP, arrayT,'chart_div',600,400);
    }
    });  
});

I know this is a lot of code 🙂 but it’s pretty simple code, to understand the flow better, here is how it`s working:

From a button input I’m calling, with AJAX, the mapped method to the drawPieChart action (which is in the ChartController class), this methods sends the response through invoking the listPieChart method (from the ChartUtils class), which returns a JsonResponse object, (which contains 2 arraylists). This JsonResponse should be converted to a JSON, because in the AJAX request, I’m telling that the request needs a JSON input (via contentType: “application/json”), and it should get it because I use @ResponseBody in the controller method mapped for this request.

I`m getting this response:

The resource identified by this request is only capable of generating
responses with characteristics not acceptable according to the request
“accept” headers ().
(HTTP Status 406)

Please correct me where I’m wrong, I just can’t get this working and I can’t figure out why…

And my servlet-context.xml:

<?xml version="1.0" encoding="UTF-8"?>
<beans:beans xmlns="http://www.springframework.org/schema/mvc"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/mvc       
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
http://www.springframework.org/schema/beans    
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
http://www.springframework.org/schema/context     
http://www.springframework.org/schema/context/spring-context-3.0.xsd">

  <!-- DispatcherServlet Context: defines this servlet's request-processing      
infrastructure -->

  <!-- Enables the Spring MVC @Controller programming model -->
  <annotation-driven />

  <!-- Handles HTTP GET requests for /resources/** by efficiently serving up
      static resources in the ${webappRoot}/resources directory -->
  <resources mapping="/resources/**" location="/resources/" />

  <!-- Resolves views selected for rendering by @Controllers to .jsp resources
    in the /WEB-INF/views directory -->
  <beans:bean 
     class="org.springframework.web.servlet.view.InternalResourceViewResolver">
    <beans:property name="prefix" value="/WEB-INF/views/" />
    <beans:property name="suffix" value=".jsp" />
  </beans:bean>

  <context:component-scan base-package="com.bla.bla" />

  <beans:import resource="classpath:springJDBC.xml" />

</beans:beans>
  • 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-11T15:27:54+00:00Added an answer on June 11, 2026 at 3:27 pm

    So the problem was that i didn’d have all the Jackson dependencies declared in pom.xml.
    These are the dependencies for your maven project in case you want Spring 3 to automatically serialize an object for you , using the @ResponseBody annotation , as a response from a method.
    Noob stuff , but I didn’t saw this mentioned in the examples that I found .

      <dependency>
            <groupId>org.codehaus.jackson</groupId>
            <artifactId>jackson-jaxrs</artifactId>
            <version>1.6.1</version>
        </dependency>
    
            <dependency>
        <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-mapper-asl</artifactId>
        <version>1.9.9</version>
    </dependency>
    
    <dependency>
           <groupId>org.codehaus.jackson</groupId>
        <artifactId>jackson-core-asl</artifactId>
        <version>1.9.9</version>
    </dependency>
    

    Also , I had to change some stuff in the ajax call for invoking the method that is returning the json object with data for the chart generation :

    $("#buttonPieGenerate").live("click", function(){
    
        $.ajax({
            url: "drawPieChart", //method from controller
            contentType: "application/json",
            data: params,
            success: function(data) {
    
            drawPieChart(data.percentages, data.topics,'chart_div',600,400);
            }
        });
    
    });
    

    I’m accessing the data in the Json object that I`m getting as a response from the call with data.percentages , data.topics .

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

Sidebar

Related Questions

I'm working on a Spring MVC 3 web application, I have some JSPs that
I am using Spring MVC for a web application and I am working with
i am working with some other people on a Spring MVC web application. If
I'm working on a reporting web application using JasperReport and Spring MVC 3 to
I am working on a web application which is based on spring MVC. We
I'm currently working on a web application using Spring MVC, and I use the
I am working under a web application which use spring mvc + mybatis +
I'm working on a reporting web application using JasperReports and Spring MVC. Now, i
I'm working on a Java web application (Adobe Flex front-end, JPA/Hibernate/BlazeDS/Spring MVC backend) and
I'm working on a Spring MVC project in which I'm using Hibernate Validator to

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.