File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Passing Data to JSP via XMLDOM Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Passing Data to JSP via XMLDOM" Watch "Passing Data to JSP via XMLDOM" New topic

Passing Data to JSP via XMLDOM

Rob Hoch

Joined: Sep 29, 2001
Posts: 3
Hello All,
I have a form with dependent data input fields on it. For example, I have a select box for states. Once a state is selected I need to repopulate a county select box with the counties for the selected state. [Note: Our target browser is IE 5 (& up). We are also trying to standardize on .JSP for presentation and J2EE for backend.]
I'm trying to come up with a way to pass information to the server to return a list of counties (via a JSP or a Servlet) without submitting the entire page.
One approach I've used before is use frames and submit from a hidden frame. The downside here is that this approach will not work if the user's browser has frames turned off.
Another approach I've considered is to write an applet to handle the interaction with the server. The only downside I can see to this approach is the overhead in loading the applet with the page.
A third approach I'm currently experimenting with is using XMLDOM within javascript to communicate with a .jsp. I'm setting up like this:
var sSendStuff = "" /*Tried passing XML and HTML data here*/
var sURL = "backend.jsp"
var bAsyncCall = false;
var oXMLhttp = new ActiveXObject("Microsoft.XMLHTTP");
oXMLhttp.Open("Post", sURL, bAsyncCall);
jsReceive2(oXMLhttp.responseText); /*This function updates the current browser screen using innerHTML*/
For testing purposes, by 'backend.jsp' is just out'ing lines of HTML:
out.print("Welcome from the land of backend.jsp. ");
out.println("<BR />");
This displays correctly on the screen. I figure if I can do this, I can do the more complicated things--db calls, data manipulation, etc.--down the road.
So far, so good. What I can't figure out how to do is pass data to the .jsp. In the .ASP world this is accomplished using the Server.CreateObject method to create an XLMDOM object.
I've tried sending various things in the .Send method, but so far nothing has worked.
Anyway, here are my questions:
1) If you've used one of these three approachs, how did they work for you? Have you thought of another way to do this?
2) Am I totally offbase with my trying to use ActiveXObject("Microsoft.XMLHTTP")? The fact that I can get it to interact and return data from my backend.jsp is encouraging, but if I can't pass data to the .jsp this approach will not work.
Any help you can give would be greatly appreciated.
Rob Hoch
Evergreen Information Systems, Inc.

Robert Hoch<BR>Evergreen Information Systems, Inc.
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13024
Seems to me you could pass the state selection to the jsp with a GET instead of a POST. That avoids the problem of writing more POST data. Something like:
sURL="backend.jsp?state=TX" ;
Also - don't you have to flush or close oXMLhttp to actually send data? You would if that was in Java.
author of:
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 17247

If having someone turn off frames is a problem, what will you do if they're using Netscape?
I HAVE to run Netscape pretty much these says - there's no IE for Linux, to say nothing of the MSXML ActiveX. I preferred IE under Windows, BECAUSE of MSXML (also because Netscape was crashing the whole system - under Linux it only crashes Netscape), but now they've got me boxed in - any IE service level high enough to be immune to NIMDA is also "immune" to Java.
If convenience is paramount and you have total control over what browser you'll support (intranet), MSXML is really cool. Notice I said "support" - users WILL sneak in copies of Opera, etc. - and it's often the case that the greatest offenders are in the most influential areas of the organization.
For Internet use, I don't recommend client-side MSXML, though - personally. I tend to avoid sites that present me with blank spots in critical parts of my browser window just because I'm not part of the "in" crowd. Java applets are a better choice there - despite what Microsoft says, there are a number of highly visible websites that won't work right if the user doesn't have Java, so chances are much better that the client will be able to work.

An IDE is no substitute for an Intelligent Developer.
Rob Hoch

Joined: Sep 29, 2001
Posts: 3
Bill & Tim,
Bill, you were right, the "GET" works just the way I wanted it. (I knew the answer was something simple like that). Tim, you raised some valid points. Right now my client says that IE is the only supported browser, which makes my job easier. I may end up with a Java applet for my 'universal' solution (when they change their minds...).
Thanks for your replies.

Robert Hoch
Evergreen Information Systems, Inc.
I agree. Here's the link:
subject: Passing Data to JSP via XMLDOM
It's not a secret anymore!