Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServletContextListener v/s init() method

which better between calling a servlet init method or implementing servlet context listener when we have to set some data on application startup.

like image 625
user1397770 Avatar asked Jul 06 '26 03:07

user1397770


1 Answers

The servlet context listener is made for that. Use it. You could use a servlet, but you would have to make sure it's started at deploy time, and before other servlets. And which one of all your servlets would have this responsibility?

like image 99
JB Nizet Avatar answered Jul 11 '26 13:07

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!