【问题标题】:unable to get init-parameter from servlet context using EL无法使用 EL 从 servlet 上下文中获取初始化参数
【发布时间】:2015-02-10 22:04:34
【问题描述】:

我正在尝试获取在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 得到这个

【问题讨论】:

  • 你有什么问题?
  • @confile 这是一个问题 -> 无法在 jsp 中使用 EL 从 web.xml 获取初始化参数值。
  • 使用EL表达式从servlet上下文中获取init参数。

标签: java jsp servlets el


【解决方案1】:

尝试使用这个表达式。

${initParam['mob']} 

或许

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

【讨论】:

    猜你喜欢
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多