How to retrieve value from web.xml in Servlet?

前端 未结 3 534
情深已故
情深已故 2020-12-19 18:05

I need to retrieve init-param value from xml to Servlet i used following code


    LoginServlet
    &         


        
相关标签:
3条回答
  • 2020-12-19 18:29

    um... it should work. Are you calling the code in LoginServlet? And the

    <servlet-class>LoginServlet</servlet-class> 
    

    is not in any package?

    0 讨论(0)
  • 2020-12-19 18:32

    I can't see a single reason, why you have to override your init(ServletConfig sc) method, since you can always get your ServletConfig by calling your inherited getServletConfig() method.

    System.out.println(getServletConfig().getInitParameter("jdbcDriver"));
    
    0 讨论(0)
  • 2020-12-19 18:37

    If you have custom initialization work to do, override the no-arg init() method, and forget about init(ServletConfig). Is it ok to call getServletConfig() method inside the no-arg init() method? Yes, an instance of ServletConfig has already been saved by superclass GenericServlet.

    http://javahowto.blogspot.com/2006/06/common-mistake-in-servlet-init-methods.html

    It is always good to use packages for classes. It enables clear demarcation.

    0 讨论(0)
提交回复
热议问题