• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Retrieve Data from an XML file using JSP

 
Ranch Hand
Posts: 43
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Not sure what I'm doing wrong and if there's an logical error in the code or the XML file. Will appreciate if someone can help. Current the JSP file is not retrieving data from the XML file.


XML file:

 


JSP




Thanks in advance!
 
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The first thing that jumps out -apart from the use of Java in JSPs, which is (and has been for a long time) bad design- is that you're not actually writing out the elements of the XML. While you didn't say what is actually being generated, you might start by replacing all code like <% eElement.getAttribute("id"); %> with <%= eElement.getAttribute("id") %>.
 
Arnob Dey
Ranch Hand
Posts: 43
Eclipse IDE Python Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Tim,

Thanks for your reply!  Okay I have moved most of the java code outside the JSP. I wrote a class called XMLDataRetriver.java. This class fetches all the data from the XML file and stores them in an ArrayList called 'xmldata'.

Now the problem is pretty simple but for some reasons I'm not able to get around it. If you observe the XML file, I need to populate each rows as shown below with data corresponding to each sheet. Any idea how can I do that?

Date             Sheet Name               Country              Primary CM              Secondary CM             Status
-------------------------------------------------------------------------------------------------------------------------------                  

Row 1

Row 2                            
 
Tim Moores
Saloon Keeper
Posts: 7585
176
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's hard to tell without knowing how the JSP and that Java class interact. Post the code you currently have.
 
Marshal
Posts: 28193
95
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Arnob Dey wrote:This class fetches all the data from the XML file and stores them in an ArrayList called 'xmldata'.  



Normally what you would do would be to create a List of some Java Bean object which represents a row in your table. Then you would put that into a response variable before forwarding to the JSP. You might have done that but your description of what you did falls short of being a useful explanation. Without understanding what you did, it's impossible to guess which of the many possible causes might be your problem.

This is also because you're trying to use a JSP for your first try at the code. Not only should you use Java code to extract data from the XML, you should also test that Java code before putting it into server components. So far... well, again, we can't tell how or whether you tested your code.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic