org.apache.jasper.jasperException

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

有不對的地方還請指教。apache

 

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

2):錯誤產生的緣由,是由於tomcat版本升級後(6.0之後),對雙引號的處理機制引發的,若是出現雙引號包含雙引號的狀況,就可能會出現這個錯誤。tomcat

3):解決辦法有好多種,大多數網上的意見是改成value=<%=""+request.getAttribute("name")%>’  這樣確實能夠解決這個報錯,可能沒法徹底解決問題,好比項目中有不少地方之前都用的是雙引號,修改起來會很是麻煩,還容易出錯。ui

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

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

       如此一來,咱們知道只要在tomcat啓動時將這個屬性設爲false就能夠解決這個問題。orm

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

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

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

相關文章
相關標籤/搜索