How to initialize a Servlet during startup with parameters?

后端 未结 4 1131
名媛妹妹
名媛妹妹 2020-12-05 04:47

Can we write an argument constructor in a Servlet? If yes, how can you call?

4条回答
  •  生来不讨喜
    2020-12-05 05:50

    You can't. Servlet is instantiated reflectively by container. If servlet spec have allowed arguments in constructor, you would have to have some complicated deployment descriptor like,

    
        MyServlet
        MyServlet
        Test
        10
        1
    
    

    I guess no one wants that.

提交回复
热议问题