0

Is there a way to return an array of strings from jsp to Ajax? How can I send it to the Ajax and read it as

xmlhttp.responseText
DalNM
  • 281
  • 3
  • 6
  • 13
  • Can I suggest employing jquery http://api.jquery.com/jQuery.ajax/ and you'll need to convert to http://www.json.org/ – NimChimpsky Aug 15 '11 at 13:21
  • Do you want to send a (java) array of strings from the server to the client via Ajax or o you want to send a (javascript) array of strings from client to server via ajax? – Nivas Aug 15 '11 at 13:23
  • Related: [How to use Servlets and Ajax?](http://stackoverflow.com/questions/4112686/how-to-use-servlets-and-ajax) Don't use JSP for "raw" Java code. – BalusC Aug 15 '11 at 13:34
  • Nivas, yes i would like to send the array of strings from the server to the client so i can display it to the the client... – DalNM Aug 15 '11 at 13:48
  • The best way to do is as in @emboss' answer: JSON is the best to go about it. There are tons of libraries available for parsing json on client as well as the server side. Just google. – Nivas Aug 15 '11 at 14:52

2 Answers2

1

DWR can be used to send array of strings to AJAX .

Using DWR for AJAX example

Easy Ajax for Java (DWR)

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

I would suggest that you look into JSON as your transport format. Encode your Java String array into JSON and send this to your Javascript. It's a very lightweight format and there exist tons of Javascript frameworks (jQuery, mootools, dojo, you name it) that make working with it a pleasure.

emboss
  • 38,880
  • 7
  • 101
  • 108