web.xml中init-param的作用

定制初始化参数:可以定制servlet、JSP、Context的初始化参数,然后可以再servlet、JSP、Context中获取这些参数值。下面拿servlet来举例:

  <servlet>
    <servlet-name>dispatcherServlet</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:springmvc.xml</param-value>
    </init-param>
  </servlet>

经过上面的配置,在servlet中能够调用getServletConfig().getInitParameter(“contextConfigLocation”)获得参数名对应的值。

参考:
https://www.cnblogs.com/fnlingnzb-learner/p/6560774.html

posted @ 2020-01-16 12:03  开局一把刀  阅读(17)  评论(0)    收藏  举报