【发布时间】:2021-04-15 08:00:04
【问题描述】:
我有 DD(web.xml 文件),代码非常简单:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>TestProject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>test</servlet-name>
<jsp-file>/result.jsp</jsp-file>
<init-param>
<param-name>email</param-name>
<param-value>example@gmail.com</param-value>
</init-param>
</servlet>
<context-param>
<param-name>name</param-name>
<param-value>Max</param-value>
</context-param>
</web-app>
注意我有两个参数(一个在 application 中,另一个在 configuration 范围内)。当我尝试将它们放入 result.jsp 时:
<html><body>
Name is: <%=application.getInitParameter("name") %>
<br>
Email is: <%=config.getInitParameter("email") %>
</body></html>
,我得到以下输出:
Name is: Max
Email is: null
我的问题很简单:“电子邮件”参数是如何获得 NULL 的?我的 JSP 文件不应该“看到”我如何配置它并返回“example@gmail.com”吗?
【问题讨论】:
标签: java xml jsp servlets parameters