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
5
  • Can I suggest employing jquery api.jquery.com/jQuery.ajax and you'll need to convert to json.org Commented Aug 15, 2011 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? Commented Aug 15, 2011 at 13:23
  • Related: How to use Servlets and Ajax? Don't use JSP for "raw" Java code. Commented Aug 15, 2011 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... Commented Aug 15, 2011 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. Commented Aug 15, 2011 at 14:52

2 Answers 2

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.

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

Comments

1

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

Using DWR for AJAX example

Easy Ajax for Java (DWR)

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.