473,506 Members | 16,954 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Pass XML string from Javascript to JSP

I have a Javascript that is building an XML string and then invokes a
JSP. I need to pass the XML string from the Javascript to the JSP.
What's the best way to do that? I am new to this technology and really
trying to learn.

Thanks,
Dan

Jun 15 '06 #1
3 2788


dm*****@ameritas.com wrote:
I have a Javascript that is building an XML string and then invokes a
JSP. I need to pass the XML string from the Javascript to the JSP.
What's the best way to do that?


It depends on how you want/can process the XML in the JSP but usually
doing a HTTP POST request with
Content-Type: application/xml
and the XML in the HTTP request body is a good idea:

var httpRequest = null;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
try {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {}
}
if (httpRequest != null) {
httpRequest.open('POST', 'whatever.jsp', true);
httpRequest.setRequestHeader('Content-Type', 'application/xml');
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
//deal with response here
}
};
httpRequest.send('<example>Kibology for all</example>');
}

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 15 '06 #2

Martin Honnen wrote:
dm*****@ameritas.com wrote:
I have a Javascript that is building an XML string and then invokes a
JSP. I need to pass the XML string from the Javascript to the JSP.
What's the best way to do that?


It depends on how you want/can process the XML in the JSP but usually
doing a HTTP POST request with
Content-Type: application/xml
and the XML in the HTTP request body is a good idea:

var httpRequest = null;
if (typeof XMLHttpRequest != 'undefined') {
httpRequest = new XMLHttpRequest();
}
else if (typeof ActiveXObject != 'undefined') {
try {
httpRequest = new ActiveXObject('Microsoft.XMLHTTP');
}
catch (e) {}
}
if (httpRequest != null) {
httpRequest.open('POST', 'whatever.jsp', true);
httpRequest.setRequestHeader('Content-Type', 'application/xml');
httpRequest.onreadystatechange = function () {
if (httpRequest.readyState == 4) {
//deal with response here
}
};
httpRequest.send('<example>Kibology for all</example>');
}

--

Martin Honnen
http://JavaScript.FAQTs.com/


Thanks so much for the info and please excuse my lack of experience
with this. Do you know what I would do in the JSP to get the
information that is set in the Javascript code?

Jun 15 '06 #3


dm*****@ameritas.com wrote:
Do you know what I would do in the JSP to get the
information that is set in the Javascript code?


You need to read in the body of the HTTP request (with an XML parser if
you want to process the XML). I don't do JSP so I can't give you code
details.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Jun 15 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
5795
by: Terry | last post by:
hi, could any1 help me with this? There're one button and one textbox on Page A. click the button: <Code Behind > Dim ClientScript As String = ""
3
6778
by: Nath | last post by:
Please help!? I am new to writing html, javascript, pretty new to MySQL but quite proficient at writing Perl and i'm a quick learner. I am building a database driven website and i am a little...
3
32120
by: DCB | last post by:
Hello. I have an easy question, likely, that has me in a headspin. I have an include file to a frames based site that basically forces frames on the end user if they visit the site and hit a...
4
13363
by: Sunny | last post by:
Hi, I am at present working on a jsp page which has a single text field. Upon entering a value in the field, i am trigerring an onChangeEvent() which calls a method of javascript. I am also...
4
4797
by: news-server.tampabay.rr.com | last post by:
Hi, Below is a stock script I found which controls a framed environment. My problem is that if a URL has a query string attached, that string does not pass through. Can someone please let me...
6
5560
by: ruca | last post by:
Hi, How can I pass an array string to javascript? I have this: in ASP.NET VB code: -------------------------------------------------------------------- Dim siteName(100) As String
2
1715
by: PJ6 | last post by:
I can probably code this up manually myself but I'd prefer to use a built-in method that I'm sure exists... I have a message box client-side control (thanks, Steve Orr) that uses the JavaScript...
3
1666
by: Boki | last post by:
Hi, Could you please advice, can javascript accept this kind of code? function resone(cnt) { alert("document.all.txt_note"+cnt) // cnt is the textbox index
3
1784
by: jmDesktop | last post by:
I have searched much but cannot find answer to this seemingly simple question. I have a function that builds an html element like this, which works fine: ...
0
7218
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7370
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7021
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5614
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5035
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
4701
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3177
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1532
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
755
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.