Can a static java code block be used in servlet?
basicallly I want to read the properties from the properties file which is saved on local machine.
I want to write this in static block so that this can be executed first time when the servlet is invoked.
Author and all-around good cowpoke
posted 7 years ago
Yes, of course static code blocks can be used in servlet code.
However, the normal practice is to initialize the kind of data you are talking about in the init() method for the excellent reason that the init method has access to the servlet context and can read init-params entries from the deployment descriptor.
Hard-coding the location of the properties file is bad practice.