標籤:des style blog http io color ar 使用 sp
JSP不支援EL運算式的解決方案
EL的全稱是Expression Language。
1.在預設情況下,Servlet 2.3 / JSP 1.2是不支援EL運算式的,而Servlet 2.4 / JSP 2.0支援。 servlets 2.4這個版本的isELIgnored預設設定為false。所以使用web.xml裡用web-app_2_4.xsd聲明的時候在JSP頁面不用特意聲明。
如何查看Servlet / JSP的版本?
開啟tomcat的common/lib 目錄下,有兩個JAR檔案: jsp-api.jar servlet-api.jar 。如果沒有,那可能是你沒有添加進來。解壓這兩個檔案,用記事本分別開啟META-INF下的MAINMEFT.MF檔案。查看Implementation-Version或Specification-Version項。
2.如果web.xml 中web-app 的 version="2.5" ,也不支援EL運算式:
[xhtml] view plaincopyprint?
- <web-app version="2.5"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
解決方法:
1.修改web.xml檔案為(Servlet 2.4 / JSP 2.0):
[xhtml] view plaincopyprint?
- <web-app version="2.4"
- xmlns="http://java.sun.com/xml/ns/javaee"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
- http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">
2.設定某個jsp頁面使用el運算式,需要在jsp頁面加上(控制單個頁面) :
[xhtml] view plaincopyprint?
- <%@ page isELIgnored="false"%>
或在web.xml檔案中加上下列代碼,這樣就不用在每個jsp頁面中指定了。
[xhtml] view plaincopyprint?
- <jsp-config>
- <jsp-property-group>
- <url-pattern>*.jsp</url-pattern>
- <el-ignored>false</el-ignored>
- </jsp-property-group>
- </jsp-config>
附:網上提供的更詳細的設定(有點囉嗦,但是可以用來參考)
[xhtml] view plaincopyprint?
- <jsp-config>
- <jsp-property-group>
- <description>指定JSP檔案的配置屬性</description>
- <display-name>jspConfiguration</display-name>
- <url-pattern>*.jsp</url-pattern>
- <el-ignored>false</el-ignored>
- <page-encoding>utf-8</page-encoding>
- <scripting-invalid>false</scripting-invalid>
- <include-prelude></include-prelude>
- <include-coda></include-coda>
- </jsp-property-group>
- <jsp-property-group>
- <description>指定htm檔案的配置屬性</description>
- <display-name>jspConfiguration</display-name>
- <url-pattern>*.htm</url-pattern>
- <el-ignored>false</el-ignored>
- <page-encoding>utf-8</page-encoding>
- <scripting-invalid>false</scripting-invalid>
- <include-prelude></include-prelude>
- <include-coda></include-coda>
- </jsp-property-group>
- <jsp-property-group>
- <description>指定html檔案的配置屬性</description>
- <display-name>jspConfiguration</display-name>
- <url-pattern>*.html</url-pattern>
- <el-ignored>false</el-ignored>
- <page-encoding>utf-8</page-encoding>
- <scripting-invalid>false</scripting-invalid>
- <include-prelude></include-prelude>
- <include-coda></include-coda>
- </jsp-property-group>
- </jsp-config>
JSP不支援EL運算式的解決方案