By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,550 Members | 2,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,550 IT Pros & Developers. It's quick & easy.

best way to post data from a javascript to a servlet

P: n/a
Hi,

I have a webpage with some javascript that constructs some data structures,
some of which contain nested structures or arrays of other structures. It's
the same order of complexity as a web.xml file, say.

I need to post the whole lot to the server and I'm not sure which is the
best way to do it. It has to be browser-independent. The only ways I can
think of are:

(a) construct a form on the fly with lots of controls, one for each
primitive value
(b) put the whole lot in a big text box (but in which format - xml?) and
then post that

Any advice or ideas would be most welcome.

Andy
Jul 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
> I have a webpage with some javascript that constructs some data structures,
some of which contain nested structures or arrays of other structures. It's
the same order of complexity as a web.xml file, say.

I need to post the whole lot to the server and I'm not sure which is the
best way to do it. It has to be browser-independent. The only ways I can
think of are:

(a) construct a form on the fly with lots of controls, one for each
primitive value
(b) put the whole lot in a big text box (but in which format - xml?) and
then post that


I would do (b), using JSON to format the data.

http://www.JSON.org/

Jul 20 '05 #2

P: n/a
I'm guessing you are not entirely a disinterested party where JSON is
concerned :)

nevertheless, I'm very tempted to give it a go, especially as you have some
java classes on hand to parse the resulting output. Now, if you could just
add an XSLT that generates JSON Javascript declarations, that would come in
very handy ;-)

I'll let you know how I get on.

Andy
"Douglas Crockford" <no****@laserlink.net> wrote in message
news:bh**********@sun-news.laserlink.net...
I have a webpage with some javascript that constructs some data structures, some of which contain nested structures or arrays of other structures. It's the same order of complexity as a web.xml file, say.

I need to post the whole lot to the server and I'm not sure which is the
best way to do it. It has to be browser-independent. The only ways I can
think of are:

(a) construct a form on the fly with lots of controls, one for each
primitive value
(b) put the whole lot in a big text box (but in which format - xml?) and
then post that


I would do (b), using JSON to format the data.

http://www.JSON.org/

Jul 20 '05 #3

P: n/a
I'd just like to report that I downloaded JSON from douglas' site and used
it to serialize my javascript objects and parse them again in java in the
servlet.

Everything worked perfectly first time except there was no definition of the
variable 'isNetscape4' (presumably I was intended to figure this out
myself). I would recommend this solution for anyone who wants to take some
data structures they have created in javascript and post them into a
servlet, or for any other of the applications mentioned on
www.crockford.com.

However, I have to say that I am not 100% convinced by the arguments on the
web site about not using XML. I think it would have been possible to use a
subset of XML (no namespaces, schemas, encodings, only the built-in
entities) and this would give the receiver of the object the option of using
full-blown XML tools to process it.

Andy
"Andy Fish" <aj****@blueyonder.co.uk> wrote in message
news:DE*********************@news-text.cableinet.net...
I'm guessing you are not entirely a disinterested party where JSON is
concerned :)

nevertheless, I'm very tempted to give it a go, especially as you have some java classes on hand to parse the resulting output. Now, if you could just
add an XSLT that generates JSON Javascript declarations, that would come in very handy ;-)

I'll let you know how I get on.

Andy
"Douglas Crockford" <no****@laserlink.net> wrote in message
news:bh**********@sun-news.laserlink.net...
I have a webpage with some javascript that constructs some data structures, some of which contain nested structures or arrays of other structures. It's the same order of complexity as a web.xml file, say.

I need to post the whole lot to the server and I'm not sure which is the best way to do it. It has to be browser-independent. The only ways I can think of are:

(a) construct a form on the fly with lots of controls, one for each
primitive value
(b) put the whole lot in a big text box (but in which format - xml?) and then post that


I would do (b), using JSON to format the data.

http://www.JSON.org/


Jul 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.