0

Currently, I have a servlet that forwards to a jsp. The jsp has access to a session attribute "current". During the loading of the jsp, the information in "current" is passed to a javascript function that generates a graph. This is all working fine. My only problem is that i'm hard coding the graph data.

How would i go about passing the data array from the servlet to the jsp. Basically, in the creerRapport function, in the 5th argument, how do I replace that with java attributes?

Any help or ideas would be appreciated.

My current code with hard coded data.

<body onload="soumettreRapport();">
<script type="text/javascript">
    function soumettreRapport() {

        creerRapport( "${current.title}",
                      "${current.type}",                                    
                       ${current.width},
                       ${current.height}, 
            [ 
             {
               key: "Cumulative Return",
               values: [
                 { 
                   "label" : "2001" ,
                   "value" : -29.76
                 } , 
                 { 
                   "label" : "2002" , 
                   "value" : 0
                 } , 
                 { 
                   "label" : "2003 , 
                   "value" : 32.80
                 }
               ]
             }
           ]
        );
    return false;
}

1 Answer 1

1

In Servlet, You need to to have JSON array as String then put this String into Request scope.

String jsonArrayString = convert(...); // Output [{key:"Cumulative Return", .... }]

request.setAttribute("jsonArrayString", jsonArrayString);

In JSP:

function soumettreRapport() {

    var jsonArray = ${jsonArrayString};

    creerRapport( "${current.title}",
                  "${current.type}",                                    
                   ${current.width},
                   ${current.height}, jsonArray );

}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.