Frage

Consider a web application, constructed from the Front Controller design pattern, included the strategy-pattern based actions, .jsp pages, javabeans and database connection, like the picture below: enter image description here

How do I assign responsibilities in my code, for loading, initializing and updating applicationscoped data?

I have read a lot on this subject, but it is hard to find what I am looking for, between all of the framework-specific-, and similar, but yet so different Q&A's.

Unlike i.e. Android, a "java web app lifecycle"-search on google, returns hits on the process of developing a web app, not running it. I am looking for a basic understanding of the life cycle, and responsibility management in web-applications.

I do already have a provider-class that is able to connect, get and sort data into java objects, from my database. Supposed that this is a best practice solution, where in the web-app lifecycle/code should i refer to/create this provider, and store the data for applicationwide use?

War es hilfreich?

Lösung

You should create it on a ServletContextListener, and store it on the ServletContext (or use a Singleton). The ServletContextListener is invoked by the Web container at application startup. The ServletContext is (among other things) a container for data that could be accessed by all requests of all sessions.

This is the JavaDoc:

http://docs.oracle.com/javaee/6/api/javax/servlet/ServletContextListener.html

And here's a tutorial;

http://www.mkyong.com/servlet/what-is-listener-servletcontextlistener-example/

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top