0

I have a jsp page. In the jsp page I do a ajax request and in response I would like to send a Map object. My first question is that is that possible.

Secondly if it's possible to send a Map object how does i retrieve it in the javascript side and how I can get all the values.

Probably I would like to send the following things from server to jsp page.

     one String Object. 
     one List<C>
     one int Object
     one List<D>  
Saurabh Kumar
  • 16,353
  • 49
  • 133
  • 212

2 Answers2

0

This can be done using DWR .

Getting Started with DWR

AJAX made simple with DWR

Ajax for Java developers: Ajax with Direct Web Remoting

Bean and Object convertors in DWR

Srikanth Venkatesh
  • 2,812
  • 1
  • 20
  • 13
0

To answer your question, this is not possible inherently.

Your jsp page is essentially executed on the server side and your response is sent back over http to your browser. Since you are making an ajax request your http response will consist of javascript code. At that point you are talking of two different languages and runtimes. i.e Java and javascript. So you cannot directly be using Map (which is a java implementation) in javascript.

Instead what you might want to try out is send a json response from your java server side. This can easily be done as javascript is an interpreted language. JSON has objects which is a name/value pair and is essentially what you want from a Map.

You might be able to use a library like DWR which does the plumbing for you to make it seem like you are invoking remote Java classes locally. But under the hoods there is a lot of stuff that goes on.

Aneesh
  • 928
  • 10
  • 20