web.xml里面可以定义两种参数:
(1)application范围内的参数,存放在servletcontext中,在web.xml中配置如下:
servlet中配置文件web.xml中的参数context-param和init-param区别<context-param>
servlet中配置文件web.xml中的参数context-param和init-param区别           
<param-name>context/param</param-name>
servlet中配置文件web.xml中的参数context-param和init-param区别           
<param-value>avalible during application</param-value>
servlet中配置文件web.xml中的参数context-param和init-param区别  
</context-param>

(2)servlet范围内的参数,只能在servlet的init()方法中取得,在web.xml中配置如下:

servlet中配置文件web.xml中的参数context-param和init-param区别<servlet>
servlet中配置文件web.xml中的参数context-param和init-param区别    
<servlet-name>MainServlet</servlet-name>
servlet中配置文件web.xml中的参数context-param和init-param区别    
<servlet-class>com.wes.controller.MainServlet</servlet-class>
servlet中配置文件web.xml中的参数context-param和init-param区别    
<init-param>
servlet中配置文件web.xml中的参数context-param和init-param区别       
<param-name>param1</param-name>
servlet中配置文件web.xml中的参数context-param和init-param区别       
<param-value>avalible in servlet init()</param-value>
servlet中配置文件web.xml中的参数context-param和init-param区别    
</init-param>
servlet中配置文件web.xml中的参数context-param和init-param区别    
<load-on-startup>0</load-on-startup>
servlet中配置文件web.xml中的参数context-param和init-param区别
</servlet>

在servlet中可以通过代码分别取用:

servlet中配置文件web.xml中的参数context-param和init-param区别package com.wes.controller;
servlet中配置文件web.xml中的参数context-param和init-param区别
servlet中配置文件web.xml中的参数context-param和init-param区别
import javax.servlet.ServletException;
servlet中配置文件web.xml中的参数context-param和init-param区别
import javax.servlet.http.HttpServlet;
servlet中配置文件web.xml中的参数context-param和init-param区别

servlet中配置文件web.xml中的参数context-param和init-param区别

第一种参数在servlet里面可以通过getServletContext().getInitParameter("context/param")得到
第二种参数只能在servlet的init()方法中通过this.getInitParameter("param1")取得

相关文章:

  • 2021-10-08
  • 2022-01-02
  • 2022-02-08
  • 2022-01-22
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-01-26
  • 2021-04-29
  • 2022-03-08
相关资源
相似解决方案