Attribute value is quoted with " which must be escaped when used within the value 問題解決


訪問JSP時,報錯:Attribute value is quoted with " which must be escaped when used within the value 。相信很多人都遇到過,以下結合本人查資料與親自實踐得到的結論。

有不對的地方還請指教。

 

1):錯誤常發生的位置 value="<%=""+request.getAttribute("name")%>"  

2):錯誤產生的原因,是因為tomcat版本升級后(6.0以后),對雙引號的處理機制引起的,如果出現雙引號包含雙引號的情況,就可能會出現這個錯誤。

3):解決辦法有好多種,大多數網上的意見是改為value=‘<%=""+request.getAttribute("name")%>’  這樣確實可以解決這個報錯,可能無法完全解決問題,比如項目中有很多地方以前都用的是雙引號,修改起來會非常麻煩,還容易出錯。

         查看tomact文檔有一段話這樣描述的“If false the requirements for escaping quotes in JSP attributes will be relaxed so that an unescaped quote will not cause an error.

If not specified, the specification compliant default of true will be used.”    這個描述針對的是tomact的org.apache.jasper.compiler. Parser.STRICT_QUOTE_ESCAPING屬性。

       如此一來,我們知道只要在tomcat啟動時將這個屬性設為false就可以解決這個問題。

       那么怎么將這個屬性設置到tomcat的system屬性中呢,有至少兩個辦法:

      一種是利用tomcat啟動的執行腳本,在執行過程中調用setenv.sh,在其中設置環境變量,如:JAVA_OPTS=%JAVA_OPTS%: -Dorg.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false

     另一種是找到conf/catalina.properties文件,在最后添加org.apache.jasper.compiler.Parser.STRICT_QUOTE_ESCAPING=false 即可。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM