JSP不支援EL運算式的解決方案

來源:互聯網
上載者:User

標籤: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?
  1. <web-app version="2.5"  
  2. xmlns="http://java.sun.com/xml/ns/javaee"  
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
  5. http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">  


解決方法:
1.修改web.xml檔案為(Servlet 2.4 / JSP 2.0):

[xhtml] view plaincopyprint?
  1. <web-app version="2.4"  
  2. xmlns="http://java.sun.com/xml/ns/javaee"  
  3. xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4. xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
  5. http://java.sun.com/xml/ns/javaee/web-app_2_4.xsd">  


2.設定某個jsp頁面使用el運算式,需要在jsp頁面加上(控制單個頁面) :

[xhtml] view plaincopyprint?
  1. <%@ page isELIgnored="false"%>  


或在web.xml檔案中加上下列代碼,這樣就不用在每個jsp頁面中指定了。

[xhtml] view plaincopyprint?
  1. <jsp-config>  
  2.   <jsp-property-group>  
  3.     <url-pattern>*.jsp</url-pattern>  
  4.     <el-ignored>false</el-ignored>  
  5.   </jsp-property-group>  
  6. </jsp-config>  

附:網上提供的更詳細的設定(有點囉嗦,但是可以用來參考)

[xhtml] view plaincopyprint?
    1. <jsp-config>  
    2.         <jsp-property-group>  
    3.             <description>指定JSP檔案的配置屬性</description>  
    4.             <display-name>jspConfiguration</display-name>  
    5.             <url-pattern>*.jsp</url-pattern>  
    6.             <el-ignored>false</el-ignored>  
    7.             <page-encoding>utf-8</page-encoding>  
    8.             <scripting-invalid>false</scripting-invalid>  
    9.             <include-prelude></include-prelude>  
    10.             <include-coda></include-coda>  
    11.         </jsp-property-group>  
    12.         <jsp-property-group>  
    13.             <description>指定htm檔案的配置屬性</description>  
    14.             <display-name>jspConfiguration</display-name>  
    15.             <url-pattern>*.htm</url-pattern>  
    16.             <el-ignored>false</el-ignored>  
    17.             <page-encoding>utf-8</page-encoding>  
    18.             <scripting-invalid>false</scripting-invalid>  
    19.             <include-prelude></include-prelude>  
    20.             <include-coda></include-coda>  
    21.         </jsp-property-group>  
    22.         <jsp-property-group>  
    23.             <description>指定html檔案的配置屬性</description>  
    24.             <display-name>jspConfiguration</display-name>  
    25.             <url-pattern>*.html</url-pattern>  
    26.             <el-ignored>false</el-ignored>  
    27.             <page-encoding>utf-8</page-encoding>  
    28.             <scripting-invalid>false</scripting-invalid>  
    29.             <include-prelude></include-prelude>  
    30.             <include-coda></include-coda>  
    31.         </jsp-property-group>  
    32.     </jsp-config> 

JSP不支援EL運算式的解決方案

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.