Win a copy of Machine Learning for Business: Using Amazon SageMaker and JupyterE this week in the Jython/Python forum
or Object Design Style Guide in the Object-Oriented programming forum!
  • 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
  • Bear Bibeault
  • Paul Clapham
  • Jeanne Boyarsky
  • Knute Snortum
  • Liutauras Vilda
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Joe Ess
  • salvin francis
  • fred rosenberger

populating jsp page from document object works for one but not multiple elements

Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
see code below:::
here is the xml string
<MAIN><RESPONSE><PAGE>success.jsp</PAGE></DATA><ITEM>This is the first item</ITEM><ITEM>This is the second item</ITEM><ITEM>This is the third one</ITEM></DATA><ERROR></ERROR></RESPONSE></MAIN>
the code below works find for displaying the <PAGE>success.jsp</PAGE> but I need to display all three items in<ITEM></ITEM> in the browser.

Any Suggestions Thanks

<%@page import="javax.xml.parsers.DocumentBuilderFactory,*,*,javax.xml.parsers.DocumentBuilder,org.w3c.dom.*" %>

<%!Document doc;%>
<title>My first template</title>
doc = (Document)request.getAttribute("theDOM");
NodeList nameItems=doc.getElementsByTagName("PAGE");
out.print("Length (" + nameItems.getLength() + ")" + "<br>");
for(int i=0;i<nameItems.getLength();i++)
String Itemvalue=nameItems.item(i).getFirstChild().getNodeValue();
out.print("Item Data as follows (" + Itemvalue + ")" + "<br>");
<br>The Data Response from IDS</br>
<br><h2><font color=#DB1260>Congrats Successful Login Welcome to Success</font></h2></br>
Thanks in advance

Sun Certified Java Programmer
Sun Certified Java Developer
I-Net Certified
A+ Certified
Network+ Certified
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't read the whole thing, but the way you declared the Document object makes it an instance variable for JSP and is therefore not Thread-safe (unsafe when accessed by multiple threads).
As an initial step, try declaring it in a scriptlet rather than a declaration block.
Ray Smilgius
Ranch Hand
Posts: 120
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good point.
I will change that now.
Space seems cool in the movies, but once you get out there, it is super boring. Now for a fascinating tiny ad:
Level Up Your Code with a Pro Java IDE
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!