以前用WSAD wizard做的,都可以在JSP頁面中解析到EL表達(dá)式,當(dāng)然前提是JSP2.0的情況下。
今天遇到了一個(gè)莫名其妙的問題。剛下載Eclipse3.3+MyEclipse6.0體驗(yàn)的過程中,遇上了解析不到EL表達(dá)式的問題。經(jīng)過好幾個(gè)小時(shí)的琢磨終于發(fā)現(xiàn)了,給大家share一下:
問題就出在建Web Project的時(shí)候web.xml聲明上。
web.xml聲明部分一般分為如下版本的xsd,
web-app_2_2.xsd
web-app_2_3.xsd
web-app_2_4.xsd
web-app_2_5.xsd
更詳細(xì)的列出各版本web.xml聲明部分吧,如下:
web-app_2_2.xsd
- <?xml?version= "1.0" ?encoding= "UTF-8" ?> ??
- <!DOCTYPE?web-app?PUBLIC? "-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.2//EN" ? "http://java.sun.com/dtd/web-app_2_2.dtd" >??
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" "http://java.sun.com/dtd/web-app_2_2.dtd">
web-app_2_3.xsd
- <?xml?version= "1.0" ?encoding= "UTF-8" ?> ??
- <!DOCTYPE?web-app?PUBLIC? "-//Sun?Microsystems,?Inc.//DTD?Web?Application?2.3//EN" ? "http://java.sun.com/dtd/web-app_2_3.dtd" >??
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
web-app_2_4.xsd
- <?xml?version= "1.0" ?encoding= "UTF-8" ?> ??
- <web-app?xmlns= "http://java.sun.com/xml/ns/j2ee" ?xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" ?version= "2.4" ?xsi:schemaLocation= "http://java.sun.com/xml/ns/j2ee???http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" >??
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.4" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
web-app_2_5.xsd
- <?xml?version= "1.0" ?encoding= "UTF-8" ?> ??
- <web-app?xmlns= "http://java.sun.com/xml/ns/javaee" ?xmlns:xsi= "http://www.w3.org/2001/XMLSchema-instance" ?version= "2.5" ?xsi:schemaLocation= "http://java.sun.com/xml/ns/javaee???http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" >??
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
確定web.xml里的xsd版本之后一定要在JSP的聲明(<%@page %>)部分加一行,如下:
<%@ page isELIgnored="false" %>
這樣設(shè)為false才能解析EL表達(dá)式。
經(jīng)過各版本的test之后....
注意!! 其中servlets 2.4(我沒記錯(cuò)的話JSP 2.0出來之后的第一個(gè)版本),這個(gè)版本的isELIgnored默認(rèn)設(shè)置為false。所以使用web.xml里用web-app_2_4.xsd聲明的時(shí)候在JSP頁面不用特意聲明。
下面是官方Documention中isELIgnored Attribute的詳解:
The isELIgnored Attribute
? Format
– <%@ page isELIgnored="false" %>
– <%@ page isELIgnored="true" %>
Purpose
– To control whether the JSP 2.0 Expression Language
(EL) is ignored (true) or evaluated normally (false).
? Notes
– If your web.xml specifies servlets 2.3 (corresponding to
JSP 1.2) or earlier, the default is true
? But it is still legal to change the default—you are permitted
to use this attribute in a JSP-2.0-compliant server
regardless of the web.xml version.
– If your web.xml specifies servlets 2.4 (corresponding to
JSP 2.0) or earlier, the default is false
更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主
微信掃碼或搜索:z360901061

微信掃一掃加我為好友
QQ號(hào)聯(lián)系: 360901061
您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。
【本文對您有幫助就好】元
