• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Bear Bibeault
  • Jeanne Boyarsky
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Piet Souris
  • salvin francis
  • Stephan van Hulst
  • Frits Walraven
  • Carey Brown
  • Jj Roberts

Passing Data to JSP via XMLDOM

Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Author and all-around good cowpoke
Posts: 13078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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:
Saloon Keeper
Posts: 22797
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
Rob Hoch
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
    Bookmark Topic Watch Topic
  • New Topic