<listener>
<listener-class>config</listener-class>
</listener>
<servlet>
<servlet-name>ProcessReg</servlet-name>
<servlet-class>ProcessReg</servlet-class>
<init-param>
<param-name>text</param-name>
<param-value>HelloWorld1</param-value>
</init-param>
public class config implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent event) {
ServletContext servletContext = event.getServletContext();
String text1 = servletContext.getInitParameter("text");
在方法
contextInitialized(ServletContextEvent event)
中,如果有两个servlet,例如,假设第二个servlet的名称为Servlet2
,并且它也有一个名为text
且值为HelloWorld2
的init-param
。那么
listener
如何知道要使用ProcessReg
servlet?如何从
Servlet2
获取param
?