473,378 Members | 1,479 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

best way to post data from a javascript to a servlet

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
3 6736
> 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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steve | last post by:
Does anyone know what is wrong with this code or why I might be experiencing this behavior? I have a Java application that submits HTTP POST requests to a servlet (with content in the body of...
1
by: Matthew Flower | last post by:
I'd like to generate a JavaScript file from a servlet. Mozilla 1.5 seems to have no problem with this, but IE 6.0 is not cooperating. I've created a very simple test servlet that writes one...
11
by: DrUg13 | last post by:
In java, this seems so easy. You need a new object Object test = new Object() gives me exactly what I want. could someone please help me understand the different ways to do the same thing in...
2
by: Rose Girl | last post by:
Hi Need some help on javascript. I need to know how to call a servlet from a javascript function. web-inf (jboss) path for servlet is: com.purpleace.ripple.admin.contacts.servlet.AdminReport...
1
by: Kevin Schneider | last post by:
I am trying to POST an XML string to a Java servlet, but I am getting the error "The underlying connection was closed: An unexpected error occurred on a receive." when I try to get the response....
3
by: Phil Campaigne | last post by:
I am developing a java/postgresql application using ant and junit. I want to deploy tested builds along with matching tables with test data in them. What is the best way to deploy the tables...
9
by: ajos | last post by:
hi all, im getting some problems in my javascript validations..... my jsp code--> 8: <head> 9: <title>Budget Master Administration</title> 10: <meta name="GENERATOR" content="Microsoft...
0
by: shlim | last post by:
Currently I'm using VB.Net to perform a http/https multipart form post to a servlet. I'm able to perform the post using HttpWebrequest via GetRequestStream(). However, the servlet returned me with...
7
by: vinodsk101 | last post by:
Hi all, I have one doubt, can we pass a variable from javascript to servlet??? In Brief, i am getting some values in javascript through jsp and the same values i want in servlet. Ya i know i...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.