无法使用EL从servlet上下文中获取init参数



我正在尝试获取web.xml文件中定义的init parameter的值。但我得到了Http Status 500异常。

在JSP文件中获取init parameter的代码:

init param: ${pageContext.servletContext.initParameter.mob}

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
  <welcome-file-list>
    <welcome-file>one/index.html</welcome-file>
  </welcome-file-list>
<context-param>
<param-name>mob</param-name>
<param-value>nokia</param-value>
</context-param>
</web-app>

当我尝试使用jsp语法在没有EL的情况下获取init参数时,没有问题。但EL导致了错误。有人能告诉我如何使用EL 得到这个吗

尝试使用此表达式。

${initParam['mob']} 

或者

${pageContext.servletContext.initParameter['mob']}

最新更新