Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to load xml/properties file at startup while loading the Application in web-Server ?

 
Prabhat Ranjan
Ranch Hand
Posts: 397
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

In Web Application 1st Web.xml file loaded and while loading the context of the web-application.

We use DispatcherServlet to load the ApplicationContext.xml file for Spring configuration file at start-up also we load faces-config.xml for JSF faces context.

How can we load any another xml file or properties file at start-up and how to configure it in web.xml file.


Regards,
prabhat

 
Evan Caballero
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
you can add a listener declaration in your web.xml file, that will "call" an implementation of ApplicationContextListener or something like this (it is part of the spring API)
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Spring is not necessary.

Servlet context listeners are part of the Servlet API.
 
sagar powar
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This might help you.

You can write custom class which implements "ServletContextListener" interface and implement method "contextInitialized()".
In this method, you will get "ServletContextEvent" object from which you can get "ServletContext" object.

Latter, this "ServletContext" object can be used to create path to external configuration files on server.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64828
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, as I've already said.
 
Bnaresh Yad
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Prabhat Ranjan wrote:Hi,

In Web Application 1st Web.xml file loaded and while loading the context of the web-application.

We use DispatcherServlet to load the ApplicationContext.xml file for Spring configuration file at start-up also we load faces-config.xml for JSF faces context.

How can we load any another xml file or properties file at start-up and how to configure it in web.xml file.


Regards,
prabhat


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic