• Post Reply Bookmark Topic Watch Topic
  • New Topic

Retrieve Data from an XML file using JSP  RSS feed

 
Arnob Dey
Ranch Hand
Posts: 41
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • 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!
 
Tim Moores
Saloon Keeper
Posts: 3570
77
  • Mark post as helpful
  • send pies
  • 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: 41
Eclipse IDE Java Python
  • Mark post as helpful
  • send pies
  • 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: 3570
77
  • Mark post as helpful
  • send pies
  • 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.
 
Paul Clapham
Sheriff
Posts: 22211
38
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!