Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dynamically Loading a XML file when the application starts

 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Ranchers,

I am trying to dynamically generate an XML file and loading it when the application starts using PL/SQL . The application uses Tomcat server.

The application uses an abc.xml file. This xml file, currently, is a static file.

I want to:
1) Dynamically generate the above XML file using some information in database.
2)Load the dynamically generated xml file when the application starts.

Point 1 is not a problem. I have problems in implementing point 2.

Can any one tell me how can I load this dynamically generated XML file when the application starts?


Cheers,
Matt
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Nothing Tomcat-specific here; moved to the Servlets forum.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Typically, startup actions are initiated using a context listener.
 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

Thanks for replying.

Can you please elaborate on dynamically loading the xml file with the help of context listener?

Any links or pointers will be appreciated.

Thanks
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64708
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A context listener has methods that trigger when an app is started and when it is stopped.

You can perform whatever action you like within these methods.
 
ankur rathi
Ranch Hand
Posts: 3830
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
... and you can use any XML parsing API (JDOM, Castor, JAXB, DOM, SAX, XMLBeans etc) to "load" an XML file (unmarshalling (XML -> Java object)).

 
Matt Thomassan
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@ Bear

I need some guidance in dynamically loading a file.

I created a small test web application that only has index.jsp. I have not created index.jsp directly. Instead, I have written a class that implements ServletContextListener interface. The contextInitialized method creates (using BufferedWriter) the index.jsp file.

When I start tomcat, it creates the index.jsp file in my C (C:\Eclipse WorkSpace\Test1\WebContent) drive (I cannot see the addition of index.jsp in eclipse yet). But when I hit index.jsp from the browser it says file not found. If I go back and refresh the eclipse project (now I can see the index.jsp file in eclipse ide), and then hit index.jsp from the browser; it displays the jsp page.

I think the problem is index.jsp page is created after the application is deployed. That may be the reason, tom cat cannot display the index.jsp page at first time. Then if I go and refresh the project in eclipse, then tom cat can display the index page.

I have made context reloadable to be true.

How can we ensure that after generating the file through contextInitialized method, Tomcat can immediately render the generated file and display it on the browser?

Please let me know how can we solve this problem?

Thanks
 
Paul Clapham
Sheriff
Pie
Posts: 20966
31
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Matt Thomassan wrote:I created a small test web application that only has index.jsp. I have not created index.jsp directly. Instead, I have written a class that implements ServletContextListener interface. The contextInitialized method creates (using BufferedWriter) the index.jsp file.


This doesn't sound like a very useful idea to me. What was your reason for doing that? Instead of something more normal, I mean. Like having the contextInitialized method just set up the data in some kind of beans and having the index.jsp file display that data using JSTL?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic