2015-02-10 58 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