servlets - WebApp. Java EE. Where I should initialize my business logic? -


i started learning java ee (jsp, servlets , patterns working database dao) , dont understand should initialize bussines logic? think create instances of in body of do*** servlet methods bad practice. p.s. app use datasource , connectionpool connection db.

you need specify requirement somehow, initialization looking for. ejb solution? pure servlet/jsp solution? etc.

normally when deploying application, after invocation application load required logic.

of course can initialize speed load, make required code run before users enter application etc.

in ejb talking @singleton , @startup annotations.

for servlet can use annotation @webservlet(name="startup", loadonstartup="0"). or put in web.xml. depends how code.

a more recommended way create own listener, , override contextinitialized , contextdestoryed methods. e.g. create db connection etc in initialized method , deregister driver in contextdestory method. use annotation @webservletcontextlistener or add listener web.xml

also java web server specific solutions exists, need check vendor.


Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -