Parameterized Constructor in Servlet

Is it possible to declare a parameterized constructor inside a servlet that is only a constructor?

If not, why?

+3
source share
4 answers

No.

Servlet instances are created by the container through reflection, and they expect to find the open no-arg constructor (the default constructor).

To configure the servlet, use the servlet settings specified in the web.xml file. They are passed to your servlet init().


Although it would be possible for the servlet container to choose a non-default constructor and overlay character strings on simple types and invoke the constructor constructively, this is not what the servlet specification requires.

; , . ; , , web.xml, : DataSource, , — .

- .

JSR, "WebBeans" (JSR 299, ), Servlets. .

+8

, .

, .

+1

<servlet-param> Spring, - , , bean.

+1

! . sevrlet. Class.forName(String classname). Class.forName(), . Class.forName() , . , service()!

+1

Source: https://habr.com/ru/post/1709685/


All Articles