2015-02-10 60 views
1

从servlet上下文获取init参数我试图获取web.xml文件中定义的init parameter的值。但我得到了Http Status 500例外。无法使用EL

代码来获得init parameter在JSP文件:

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。但是EL引起的错误。谁能告诉我如何得到这个使用EL

+0

什么是你的问题? – confile 2015-02-10 22:33:31

+0

@confile这是一个问题 - >无法从jsp中使用EL在web.xml中获取init参数值。 – JPG 2015-02-10 22:52:41

+0

使用EL表达式从servlet上下文获取init参数。 – 2015-04-26 16:40:30

回答

2

尝试使用这个表达式。

${initParam['mob']} 

或许

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

+0

感谢您的支持。首选方案解决了我的问题。 – JPG 2015-02-10 22:26:40